What is it?
ZLib is capacitors, pistons, and servos. ZLib is a box of assorted LEGOs. ZLib is a stocked pantry. ZLib is evolution towards order but without form.
Or, less magniloquently, Zlib is a single function library containing my most useful functions. I grew tired of tweaking a function that was in multiple scripts and making sure I had changed them all. It would be nice, thought I in my customary italics, to have it in just one place. Thus, this library, which can be easily imported into any script. In choosing which functions to include, I have tried to select only those functions which are a) super useful, or 2) needed by another of the included functions.
Basically, ZLib is inventing the wheel. It makes it much easier for scripters to do things like make bicycles, cars, and monster trucks.
First, an important message:
Now to get down to it. Quite a few scripts on this forum use functions which are in ZLib, meaning you should have zlib.ash somewhere in your scripts directory. Some scripts which update via SVN will automatically install ZLib for you (in case you're wondering where it came from). A lot of scripts are also using ZLib's "script settings", which is a way to keep script configuration variables stored locally, outside the script. This allows you to configure scripts without needing to actually edit them -- and even when you update the script your settings for that script will remain unchanged. You can type "zlib vars" into the CLI to see your current ZLib settings and their values. You can also edit these settings by calling ZLib directly, as described here. Other than editing settings, you won't actually "run" this script, but a lot of other scripts will.Are you getting this error?
Expression syntax errors for 'modifier_eval()':
Expected <something>, found <something else> (zlib.ash, line 188)
If so, it's not ZLib's fault. Repeat, ZLib is not responsible, so do not report that error in this thread. It means that a script which includes ZLib sent a bad formula to ZLib to be evaluated. In the vast majority of the cases I've seen so far, the responsible script is BatBrain, so please go report the error there rather than here. Thank you.
For Script Authors
I feel pretty confident that nearly all of these functions are useful and have broad applications. With ZLib you can iterate through your kmail easily, make sure your users keep your script current, or allow your script to always use a current version of a publicly-editable data file. You can work more easily with strings, specify verbosity levels for individual print commands, and display numbers in a human-readable way. ZLib even gives you some functions you might miss from other programming languages like abs(), minmax(), and join(). It's very easy to avail yourself of these functions, and add commonly useful functionality to your script without having to do all the legwork from scratch. StDoodle has been so good as to add ZLib documentation to the ASH Wiki -- so I will be maintaining the function list there rather than in this thread.
You can type "ashwiki zlib" in the CLI to visit that page easily from within mafia.
How to use it:
To include this library in your script, simply add the following at the top of your script:
Then all these functions will be available in your script. Have fun!Code:import <zlib.ash>
To download this script, simply type
in the CLI. Mafia will automatically install it in your scripts directory.Code:svn checkout https://svn.code.sf.net/p/zlib/code
6.14.09: r1 posted.
7.11.09: r2: added my_defstat().
7.25.09: r3: Introduced setvar() as a solution to per-character script settings. Also added spaces_to_underscores() and minmax(), and versions of send_gift() and kmail() that allow you to specify the message inside gifts, for users that need that degree of control. Some coding tweaks to get_safemox() and my_defstat(). Call ASH's recent set_location() in obtain().
7.28.09: r4: Include some more settings: automcd, is_100_run, and defaultoutfit. Include new old function auto_mcd().
9.01.09: r5: New int setting unknown_ml (default is 150) -- auto_mcd() uses this as the assumed strength for unknown or combatless zones. FTF will also use this as the ML of unknown monsters. Added error(). kmail() now saves messages in your outbox.
9.26.09: r6: added script settings editing functionality when called directly. Removed spaces_to_underscores(), since ASH's replace_string() is better.
10.10.09: r7: resist() now takes advantage of Exotic Parrot. auto_mcd() skips MCD-sensitive boss zones. Mostly fixed a bug with the return value of obtain() for choiceadvs. Also, some changes for familiars: first, the is_100_run setting is now a familiar, rather than a boolean (default is none). Second, best_fam() now can prioritize familiars.
10.19.09: r8: removed min() and max() because they were added to ASH! w00t! Also changed minmax() to use floats (will not require script editing and allows for greater precision when needed). Fixed error calculating possible parrot weight (had accidentally swapped the parameters for numeric_modifier()).
11.5.09: r9: added eval(). Converted check_version() to merely wait an annoying interval rather than popping up an annoying dialog. Here's hoping it doesn't facilitate lots of bogus bug reports. Also, it now uses a regex provided by Bale, which I inserted using tweezers and rubber gloves. Also you can now type "zlib vars" to see your current settings.
11.15.09: r10: added auto_mcd(int safemox) for cases where you want to fight a single monster (i.e. item-use-invoked combats).
12.03.09: r11: also added auto_mcd(monster mob) as a shortcut for the above. You now have a full range of auto-MCD options. Kmails (and gifts) no longer change the message when splitting kmails with more than 11 types of item.
12.30.09: r12: added abs() for both ints and floats. Added vprint() as a verbosity-sensitive wrapper for print() and abort(). Deprecates error()
1.23.10: r14: added vprint_html() to complement vprint(). Added load_current_map() for use by scripts to auto-update data files using the Map Manager.
2.07.10: r15: revert vprint(msg,0) to abort() rather than exit due to unwanted results when vprint's return value was captured. Add has_goal() for both items and monsters. Auto-MCD-ing skips Slime Tube. As forewarned, removed error().
2.27.10: r16: don't url_encode() kmail messages, now that mafia appears to handle that automatically. Smarter MCD-ing (now also skips for monsterless zones, a few other tweaks).
3.21.10: r17: excise() now accepts empty strings for both start and end to specify the ends of the string. MCD-ing now uses unknown_ml correctly (stupid parenthese). minmax() actually uses min() and max(). Sending only meat in a gift now works correctly. Stop calling ZLib releases "builds" in the changelog since they are not compiled -- instead use "r" for "release". Seriously, I was annoying myself with that.
4.19.10: r18: added rnum() for human-readable numbers. Removed all the commented WOSSMAN stuff since relay is the future of ZLib settings editing.
4.25.10 r19: fixed recursion bug in has_goal(), and added versions for monsters and locations. All three versions now return floats.
5.01.10 r20: Happy May Day! Fixed has_goal() for bounty items. Removed to_element() since it is now in ASH. Auto-MCD now uses appearance_rates() to determine which monsters to skip, with a few choiceadv-sensitive exceptions. Now locations like Haunted Bathroom (GMoB) and Primordial Ooze (Cyrus) will MCD correctly.
11.10.10 r21: Happy payday! (Well, for me at least.) Added normalized(). Normalize ZLib settings in setvar(). Recent KoL changes allowed for solving the moxie sign MCD detection issue. Account for combat frequency modifier in has_goal(location). Changes to check_version(): it now returns a string, usable by relay scripts. Allow for specifying a required mafia revision number in the checked thread.
1.26.11 r22: ASH's exponentiation operator will shortly be **, not ^. Consider unspaded drops as having a barely nonzero drop rate, rather than 0. Fix regex in check_version(). And: normalized() can now normalize comma-delimited lists of mafia types.
2.16.11 r23: emergency fix for new Knob locations.
5.01.11 r24: Added load_kmail(), isxpartof(), and join(). Given the new kmail record type, added a kmail(kmessage). The new function also allows has_goal() to return percentages for ingredients of goals.
5.12.11 r25: Allow for negative fromid's in load_kmail(). Normalization of script settings is case-sensitive. Print clicky link in check_version(), and try to be a little bit smarter about versions formatted n.n.n and suchlike.
5.17.11 r26: Added equals(string, string) as a case-sensitive == operator for strings. Further tweaks to check_version(): 1) smartly handle post-version-check updates, and b) only run the comparison logic if the strings are actually different.
5.18.11 r27: Added be_good(item) for checking whether an item will anger bees. Incorporate that into use_upto(). ASH's in_mysticalty_sign() is now canadia_available().
6.06.11 r28: More sign changes for auto_mcd(). Added really cool function process_kmail() for really simple kmail parsing.
8.02.11 r29: Added coinmaster type to setvar() and normalized(). Only remove HTML bits from kmails that include items/meat. When called multiple times in a row, don't parse already deleted kmails in process_kmail().
9.16.11 r30: Never purchase items in use_upto() in Fistcore, regardless of the purchase parameter. Change be_good() to accept a string and filter 'b' familiars in best_fam(). Make has_goal() speculative. Rather than just show an error message, print a substring-matched list of settings when called from the CLI with text that doesn't match a setting name.
10.15.11 r31: Added phylum type to setvar() and normalized(). Previous update's matching should have been case-insensitive. Eliminate infinite recursion in isxpartof(). Move all version checking into a single map, for true once-daily checking.
11.28.11 r32: Significant repurposing of be_good(): it now checks that the supplied string is safe for whatever path you're on, not only Beecore. Add commas in rnum() starting at 1000, not 10,000. Allow obtain() to get flyer ML and insults now that those are valid conditions. Make my_defstat() speculative.
12.02.11 r33: Add optional usespec parameter to my_defstat(). If true, the return value will be speculative. If false or no value is supplied, the value will be non-speculative, as before.
2.16.12 r34: Avatar of Boris support for be_good(). Allow "autostop" as a condition for obtain().
3.17.12 r35: Huge speed improvement to all forms of has_goal() due to ASH's new goal functions. Additionally, all functions that previously used speculation now include optional usespec parameter, a la my_defstat(). Only perform "whatif quiet" to initialize values if spec is empty.
5.09.12 r36: New function tower_items(). Consider empty maps equivalent to out-of-date maps in load_current_map(). Fix to has_goal(location) for areas with unknown combat rates.
7.12.12 r37: Fix rnum() after mafia's change to floats. Introduce two new functions for finding the worth of items: mall_val() and sell_val().
6.17.13 r38: ZLib is now hosted on SourceForge, and accessible with mafia's new SVN capability.
Since migrating to SVN, the changelog for updates made after 2012 can be found on SourceForge. However, I will continue to post more in-depth release notes in this thread.