Page 1 of 121 1 2 3 11 51 101 ... LastLast
Results 1 to 10 of 1210

Thread: ZLib -- Zarqon's useful function library

  1. #1
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,392

    Lightbulb ZLib -- Zarqon's useful function library

    ZLib

    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.

    For Users

    First, an important message:

    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.
    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.

    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:
    Code:
    import <zlib.ash>
    Then all these functions will be available in your script. Have fun!

    ~Z~

    Installation

    To download this script, simply type
    Code:
    svn checkout https://svn.code.sf.net/p/zlib/code
    in the CLI. Mafia will automatically install it in your scripts directory.


    Changelog
    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.
    Last edited by zarqon; 02-24-2015 at 01:30 PM.
    Sig by JakAtk
    My scripts: One-Click Wossname | Om******t (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mer********d (?!) | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | CanAdv | Script Registry | Map Manager | About Bats
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  2. #2

    Default

    This is really useful! These functions look like they'd help me with my own ASH scripting. Thanks for sharing!

  3. #3
    Senior Member matt.chugg's Avatar
    Join Date
    Nov 2006
    Posts
    617

    Default

    shiny! (been waiting for this since you mentioned it in the other thread )

  4. #4
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    Excellent! On the off chance that you'd like to include any of the functions from one of my scripts (including ascend.ash), please feel free to do so. One suggestion: Alhifar's excellent run_adv(). I have a slightly modified version of it in ascend.ash, and I find it to be very handy.

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    526

    Default

    If you would like to include run_adv(), let me find where I put the updated version, the version posted earlier on here had a bug or two that I have corrected.

  6. #6
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    Important question: How do we handle the issue of script A including script B, when both A&B include zlib? You can see how this is a challenge for something like ascend.ash, which includes many subscripts, many of which are also used independently.

    Another suggestion: tools related to safemox. Determine safemox for an area, find the difference between safemox and what you've deemed acceptable via threshold, etc.

    Another another suggestion:

    int VERBOSE = 2;
    boolean verbose(int lvl,string msg)
    {
    if (lvl <= VERBOSE)
    {
    print("Level "+lvl+": "+msg);
    return true;
    }
    return false;
    }
    I've often meant to put this in a common include, so I can include copious debug statements that can be easily eliminated from actual operation.

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    526

    Default

    The following bit of code should handle any choice adventure supported by mafia, as well as combats, and regular non-combats. It will return the full text of the LAST page visited by the function, just as run_combat() does.
    Code:
    string run_adv( string page_text )
    {
    	while( contains_text( page_text , "choice.php" ) )
    	{
    		matcher m_choice_adv_num = create_matcher( "whichchoice value=(\\d+)" , page_text );
    		m_choice_adv_num.find();
    		string choice_adv_num = m_choice_adv_num.group( 1 );
    		
    		string choice_adv_prop = "choiceAdventure" + choice_adv_num;
    		string choice_num = get_property( choice_adv_prop );
    
    		if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
    
    		string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
    		page_text = visit_url( url );
    	}
    	if( contains_text( page_text , "Combat" ) ) page_text = run_combat();
    	return page_text;
    }

  8. #8
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    Excellent work Alhifar. For unsupported choiceadvs, can we do something more robust than abort()? It'd be nice to print an error and continue operation.

  9. #9
    Senior Member
    Join Date
    Jul 2008
    Posts
    526

    Default

    What is there to continue? You would be stuck in an infinite loop in the choice adventure, because it doesn't know what to choose. I personally wouldn't be comfortable having it make a default choice.

    In an ideal world, I would be able to open up the mini-browser to the page in addition to aborting, but that seems like it would be way more work than it is worth for Veracity/Jason.

  10. #10
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    Hm. Yup, you're right. Not much else you can do.

Similar Threads

  1. Replies: 1
    Last Post: 11-25-2013, 06:48 PM
  2. StDoodle's Libray - Another function library
    By StDoodle in forum Scripting Discussion
    Replies: 6
    Last Post: 10-29-2013, 10:04 PM
  3. ROFL -- Ridiculously Overelaborate Function Library
    By Catch-22 in forum Informational Scripts
    Replies: 6
    Last Post: 06-07-2012, 07:28 AM
  4. is there a way to see what a function within zlib returns?
    By maximillian the red in forum Community Support
    Replies: 6
    Last Post: 10-03-2011, 07:33 PM
  5. Adventure Function Library
    By muffins in forum Scripting Discussion
    Replies: 9
    Last Post: 05-06-2006, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •