ZLib -- Zarqon's useful function library

Heh. You really liked that, eh? It took longer to write that function to time my dice rolls than I actually spent rolling dice. I'd be happy if that time wasn't totally wasted.
 
Just seems useful in terms of general timing things. If it doesn't get implemented as a part of zlib, I'll probably set some sort of time_to_string alias. :)
 
Hey I was troubleshooting as to why my Slimeling was not being selected in the nemesis quest as my best item familiar and it led me to zlib's best_fam function. if i'm understanding it correctly it checks a preloaded mapping of familiars using load_current_map, which based on my wiki search seems to indicate it pulls from Zarqon's Map Manager, located here. The best_familiars one appears to not have been updated since 2009, so I'm wondering if that's still truly the source or if I need to look elsewhere.
 
Infinite loop when trying to find wad of dough or flat dough through has_goal. Since the wad of dough creates the flat dough and vice versa, they'll keep flipping back and forth in isxpartof until mafia aborts it.
 
r31 Update!

  • Added the new phylum type to setvar() and normalized().
  • I could have sworn I made that substring matching case-insensitive for the last update, but no. Fixed that.
  • Put a cap on the recursion in get_parent() to squash the bug mentioned by by Theraze.

And the biggie: In the interest of speeding things up for people playing multiple characters, moving global data out of user properties, and of course reducing server hits, I moved all version checking info -- for both scripts and maps on the Map Manager -- out of properties and into a single map (zversions.txt). Now, each script or map will really only be checked once per day, as opposed to once per day per player.

For those of you with OCD tendencies (i.e. KoLmafia users), you'll probably want to go through your <name>_prefs.txt file(s) and remove the previously used properties. Remove all properties beginning with "_version_" or "map_":

_version_somescript=3.4
map_somemap.txt=2011-09-06T04\:34\:58-05\:00, checked 20111013


It is almost entirely harmless to leave them there as staid memories of a bygone era, but after deleting them you will feel cleaner, smoother somehow; like a sleek, aerodynamic penguin slipping effortlessly through clear Antarctic waters.

Enjoy!
 
I am getting this message in gray constantly (in the CLI window):

Running ZLib version: r31 (current)

The only way I could figure out how to fix it was to do this:

if (sameornewer(thisver,zv[prop].ver)) { return ""; }
# if (sameornewer(thisver,zv[prop].ver)) { vprint("Running "+soft+" version: "+thisver+" (current)","gray",w); return ""; }


Is there a better way?
 
Last edited:
Yeah... I'm guessing that this line didn't get changed:
PHP:
string check_version(string soft, string prop, string thisver, int thread) { int w = 1; string page; matcher find_ver;
The value of int w is what level those default messages will be displayed... I'd suggest just throwing a 0 on the end and using this:
PHP:
string check_version(string soft, string prop, string thisver, int thread) { int w = 10; string page; matcher find_ver;
 
Yarrr, methinks those two numbers be switched arrround.

Fixed. Should be verbosity 1 the first time, verbosity 8 subsequent times. Re-grab from the first post if it's annoying you.
 
Code:
Function 'to_phylum( string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts (zlib.ash, line 77)

KoLmafia.exe v14.8 (latest as of this post).
 
I was unable to set a var before a script created it:

gCLI said:
> zlib spaaace_othergoal = distention pill

Running ZLib version: r31 (current)
No setting named 'spaaace_othergoal' exists.

Even the ashq trick couldn't work around it, for some reason I don't understand:
gCLI said:
> ashq import zlib; setvar("spaaace_othergoal", $item[none]);

spaaace_othergoal could not be found ()

I had to run the script, then abort it to change the setting.

As far as my eyes detect the variable name was the same.
Code:
setvar("spaaace_othergoal", $item[none]); // set to e.g. distention pill or synthetic dog hair pill.
 
The "ashq trick" didn't work for you because you didn't quote the name of the file being imported - single quotes, double quotes, or angle brackets are accepted. The unquoted form of the import statement has to be the only thing on the line, which isn't possible in an ashq command.
 
Just in case this helps you: the suggested design for using setvar() is to put them at top level just above your main(), followed immediately by check_version(). This way they are not at the top of your script and thus won't trick users into thinking they can edit them in the script, and a first-time user can run the script and have a few seconds to abort during version checking after the vars have been set, in the case that they would like to configure any of the settings to non-default values.
 
The first time you run a script, would it make sense for zlib to stop the script's execution if it detects that new zlib vars have been added? With a message like "the following variables have been added, please configure them and execute the script again", followed by a list of the settings and their default?

EDIT: the only drawback is finding a way to detect which call to setvar() is the last one in the script.
 
Last edited:
That sounds like an action to be taken by the script calling zlib. Something like:

PHP:
boolean config_vars = false;
if(!(vars contains newvar))
   config_vars = true;
setvar(newvar, "DATA");
if(config_vars)
   abort("newvar was just added as a zlib variable. Please configure it now and then restart this script.");
 
Yeah... especially because if it did that automatically, things that trigger repeatedly like consult scripts would probably fail the first round and do whatever your next action is, and you'd never actually see that you were supposed to consult unless you looked into why you had one round of "attack with weapon" instead of drunken punching or whatever else you'd have done. :)
 
The "ashq trick" didn't work for you because you didn't quote the name of the file being imported - single quotes, double quotes, or angle brackets are accepted. The unquoted form of the import statement has to be the only thing on the line, which isn't possible in an ashq command.

Hmm, I could have sworn I've done that before. For instance this works fine:

Code:
ashq import nemesis; nemesis_Disco_Bandit();

Just in case this helps you: the suggested design for using setvar() is to put them at top level just above your main(), followed immediately by check_version(). This way they are not at the top of your script and thus won't trick users into thinking they can edit them in the script, and a first-time user can run the script and have a few seconds to abort during version checking after the vars have been set, in the case that they would like to configure any of the settings to non-default values.

Perhaps that guidance should be added to the wiki page? (http://wiki.kolmafia.us/index.php?title=Zlib if I understand correctly)

That sounds like an action to be taken by the script calling zlib. Something like:

PHP:
boolean config_vars = false;
if(!(vars contains newvar))
   config_vars = true;
setvar(newvar, "DATA");
if(config_vars)
   abort("newvar was just added as a zlib variable. Please configure it now and then restart this script.");

Thanks for the code, I'll add that to my script.
 
Last edited:
Back
Top