ZLib -- Zarqon's useful function library

slyz

Developer
Oh, I always assumed that this bit would go somewhere in the main script. In that case, yes, the "foreach version" wouldn't really be useful since you would need the scripts it checks to have run at least once before.

Regarding using file_to_map() on scripts, that would have been very interesting, but it doesn't seem to be working as expected:
Code:
> ashq string[int] t; file_to_map("zlib.ash",t); foreach i,s in t print(s);

X - gender (-1=male, 1=female)
The line that was read is a comment in zlib.ash on line 152...
 

Theraze

Active member
That's odd... wonder if there's any way to actually load the text of a script into a map so that you can parse it. Most scripts that I try return a single empty result... To display using proxy records, you can drop it down to this, though it still doesn't work:
> ash string[int] t; file_to_map("zlib.ash",t); t;

Returned: aggregate string [int]
0 => X - gender (-1=male, 1=female)
 

fianor

Member
check_version() prints a message if your script is outdated. It also returns a string which contains almost the same message (almost). In the code you are using, the string c only serves to check if check_version() returned empty strings only. You really don't need to print it, but that's where the second message comes from.
Try using the first version I posted, with abort("Scripts are not current") instead of abort(c).

Right, I understand that, however the 2nd message is the good one. The first message, while giving the same info DOES NOT have the direct link to the forum post where I can download the update while the second message does. I'd rather have and ugly script with 2 replies, one of which is a "clickable link" than a prettier one requiring me to copy/paste the link.

In the version with the foreach, I just create the to_check map which contains the names of the properties and the versions of each script you are currently running. If the property is different than the current version, then the script is outdated and it aborts.

There isn't any thread checking, and you wouldn't really need to add a check_version() since that is already done when you import the scripts.

head ... hurt .... I think I'm probably just not an advanced enough programmer / well versed enough in the lingo to understand this version yet.

Theraze is correct in that I do not have an import call to most of these scripts in my main farming script. I do import zlib, but the others are all used elsewhere. BBB is of course only called up by mafia between fights. I have modified it to call NeoLibram also between fights. BatBrain is only called upon by SmartStasis, which is in turn only used by my CCS. My actual farm script never calls upon any of them. In fact zlib is only being imported by it to use check_version() in this function, I don't use it for anything else.

For testing purposes only, here is the entire script I'm running:

Code:
void main() {
    string [ string ] to_check;
    to_check[ "zlib" ] = ": 24";
    to_check[ "batbrain" ] = "1.0";
    to_check[ "SS" ] = "3.3";
    to_check[ "NeoLibram" ] = "1.1";
    to_check[ "automcd" ] = "2.5";
    foreach s, v in to_check
        if ( get_property( "_version_" + s ) != v )
            abort( **whatever adjusting I do for testing output is being done here** );
    print ("Scripts are current", "red"); 
}

Now when I run that script, on a clean login (after having adv'd today, but I closed out mafia completely, so I assume all variables are cleared), it does actually appropriately respond (using what I can only assume is black magic of some sort) during the if statement with current or not. If I change one of the version numbers it appropriately responds not current, with them correct is says they're current. How in the hell is this checking if I'm not importing them and it's not going to the forum thread? I'm so completely lost on how this is working my head may well explode. This is some form of voodoo you're using on my head isn't it? I'm sorry for whatever I did to piss you off, please stop trying to kill me with ash.voodoo.
 

slyz

Developer
Right, I understand that, however the 2nd message is the good one. The first message, while giving the same info DOES NOT have the direct link to the forum post where I can download the update while the second message does. I'd rather have and ugly script with 2 replies, one of which is a "clickable link" than a prettier one requiring me to copy/paste the link.
The first message is the one printed by zlib's check_version(). Its link isn't clickable, but it would be easy to make it so and Zarqon will probably change that.

The second message is the string check_version() returns. It was meant to be used in relay scripts, but printing it in the gCLI as you do also works.

Now when I run that script, on a clean login (after having adv'd today, but I closed out mafia completely, so I assume all variables are cleared), it does actually appropriately respond
Those properties are cleared after each rollover. So checking them wouldn't work if those scripts haven't been called yet that day. Simply import the scripts to make it work:
PHP:
import zlib.ash;
import batbrain.ash;
import smartstasis.ash;
import NeoLibram.ash;
import BestBetweenBattle.ash;

void main() {
    string [ string ] to_check;
    to_check[ "zlib" ] = ": 24";
    to_check[ "batbrain" ] = "1.0";
    to_check[ "SS" ] = "3.3";
    to_check[ "NeoLibram" ] = "1.1";
    to_check[ "automcd" ] = "2.5";

    foreach s, v in to_check
        if ( get_property( "_version_" + s ) != v )
            abort( "Scripts are not current" );
    print ("Scripts are current", "red"); 
}

EDIT: if you are confused by foreach, you should read up on the Mafia Wiki
 

fianor

Member
slyz said:
The first message is the one printed by zlib's check_version(). Its link isn't clickable, but it would be easy to make it so and Zarqon will probably change that.

The second message is the string check_version() returns. It was meant to be used in relay scripts, but printing it in the gCLI as you do also works.


Yeah I get that, was just trying to figure out how to "turn off" the first one in this situation. I found a better way though I guess. To make sure it always gives the linked version of the message, I changed zlib's check_version() to this (red is removed/commented out, green added):

Code:
	string check_version(string soft, string prop, string thisver, int thread) { int w; string page;
   switch (get_property("_version_"+prop)) {
      case thisver: return "";
      case "": vprint("Checking for updates (running "+soft+" ver. "+thisver+")...",1);
         page = visit_url("http://kolmafia.us/showthread.php?t="+thread);
         matcher find_ver = create_matcher("<b>"+soft+" (.+?)</b>",page);
         if (!find_ver.find()) { vprint("Unable to load current version info.",-1); set_property("_version_"+prop,thisver); return ""; } w=19;
         set_property("_version_"+prop,find_ver.group(1));
         if (find_ver.group(1) == thisver) { vprint("You have a current version of "+soft+".",1); return ""; }
      default:
        string msg = "<big><font color=red><b>New Version of "+soft+" Available: "+get_property("_version_"+prop)+"</b></font></big>[COLOR="seagreen"]<br><a href='http://kolmafia.us/showthread.php?t="+thread+"' target='_blank'>Upgrade to "+get_property("_version_"+prop)+" now!</a>[/COLOR]";
         vprint_html(msg,1);
         [COLOR="seagreen"]wait(1+w);[/COLOR]
[COLOR="red"]#         msg += "<br><a href='http://kolmafia.us/showthread.php?t="+thread+"' target='_blank'>Upgrade to "+get_property("_version_"+prop)+" now!</a>";[/COLOR]
         find_ver = create_matcher("\\[requires revision (.+?)\\]",page);
         if (find_ver.find() && find_ver.group(1).to_int() > get_revision())
            msg += " (Note: you will also need to <a href='http://builds.kolmafia.us/' target='_blank'>update mafia to r"+find_ver.group(1)+" or higher</a> to use this update.)";
[COLOR="red"]#		 vprint("Upgrade "+soft+" from "+thisver+" to "+get_property("_version_"+prop)+" here: http://kolmafia.us/showthread.php?t="+thread,"blue",1);wait(1+w);[/COLOR]
         return "<div class='versioninfo'>"+msg+"</div>";
   } return "";
}

foreach I understood, "_version_scriptname" being saved in vars I didn't. Now I get it. But since the foreach version of the testing doesn't return the check_version() messages then:

Code:
void DWS_script_updates() {
 	string c;
    c += check_version("ZLib","zlib",": 24",2072);
    c += check_version("BatBrain","batbrain","1.0",6445);
    c += check_version("SmartStasis","SS","3.2",1715);
    c += check_version("Neo's Libram Script", "NeoLibram", "1.1", 2591);
    c += check_version("Best Between Battle Script Ever","automcd","2.5",1240);
    if ( c != "" ) abort("");
    print ("Scripts are current", "red");
}

combined with the zlib change is working perfectly for me. I'm not sure if I fixed zlib properly or not, and don't know 100% if the "Note: You will also need ... " bit will go off as intended, but I've haven't seen any scripts using that so I don't know how to test it.
 
Last edited:

Bale

Minion
I need to report a bug with zlib resulting from a server side change to KoL. It's been a few days, but the bug only struck me intermittently so I wasn't sure what was causing it until now. Finally I figured out why registry was sometimes deleting the wrong kmails!

The api used to report the fromid of 'Your Pen Pal' as 0. That was changed! Now the fromid is -1. Unfortunately the matcher doesn't consider the possibility of a negative number so the id of a message from 'Your Pen Pal' gets assigned to the following message. That is obviously bad, but easy to fix. The following matcher should handle it fine:

Code:
   matcher k = create_matcher("'id' =\\> '(\\d+)',\\s+'type' =\\> '(.+?)',\\s+'fromid' =\\> '(-?\\d+)',\\s+'azunixtime' =\\> '(\\d+)',\\s+'message' =\\> '(.+?)',\\s+'fromname' =\\> '(.+?)',\\s+'localtime' =\\> '(.+?)'"

Now I shouldn't be at risk of losing my kMail message from my pen pal tomorrow.
 
Last edited:

Gdunge

Member
I have been having problems when setting "zlib verbosity = 9". (I'm trying to get debug info for an issue with SmartStasis not Olfacting.)

When verbosity is 9, the KoLmafia interface starts to break down. The main frame goes blank, although I can click on it and controls will appear (if I clicked on their location). If I choose (for example) Adventure from the Window menu, I usually get a mostly blank window with a few things in it: a Begin button (from the main adventure window, I think) and a blue horizontal thermometer (also from the main adv window).

The thermometer contains the following message, which I assume is important:

net.sourceforge.kolmafia.swingui.AdventureFrame could not be loaded

I've also seen "CommandDisplayFrame", "MallSearchFrame", "GearChangerFrame", "MaximizerFrame", and "StoreManageFrame" when choosing different interfaces from the Window menu. But sometimes, I just get a completely blank frame.

If I quit KoLmafia and restart, then set "zlib verbosity = 8", all is well again.

Any ideas?

I am running on a Mac, OS X 10.6.7. Java version:

[prospero:~] dougw% java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)

Thanks!
 

slyz

Developer
I think this is a problem with BatBrain's to_html(advevent a, boolean table). stasis_action() and stun_action() use it to print things in the gCLI when your verbosity is 9.
 

Bale

Minion
One more comment regarding load_kmail():

It should take a string parameter so that the user can define the "for" parameter. After all, it would be weird for someone else to make use of loat_kmail() in their script and have CDMoyer informed that the person is using "registryscript" when they are not.

Please add that (perhaps by overloading the function) when you fix the bug in load_kmail().
 

dwhite

New member
vprint("Evaluating '"+b.to_string()+"'...",10+(m.find() ? 0 : 1+to_int(is_integer(b))));
return modifier_eval(b.to_string());
}

Getting an error that says ? found when ) expected in the r25 version.
 

Theraze

Active member
Not sure how much we care about it, but the new zlib kicks out the following warning:
Checking for updates (running ZLib ver. r25)...
_version_zlib => r25
The string "r25" is not an integer; returning 25 (zlib.ash, line 178)
The string "r25" is not an integer; returning 25 (zlib.ash, line 178)
The string "r25" is not an integer; returning 25 (zlib.ash, line 179)
The string "r25" is not an integer; returning 25 (zlib.ash, line 179)
You have a current version of ZLib.

Also, the file still internally calls itself 24 in the header, though that's fairly irrelevant to anything. :)
 

ajandaj

New member
The attachment here in the forum for the ZLIB download appears broken.

EDIT: Never mind... fixed.
 
Last edited:

slyz

Developer
This is Mafia giving a warning because of a to_int( string ) on a non numeric string:
Code:
> ashq to_int("r25");

The string "r25" is not an integer; returning 25 ()
 

zarqon

Well-known member
ZLib is one of the few scripts that will show this warning.

Considering that so many scripts use n.n[.n] versioning, ZLib now compares individual sections of the version string (delineated by periods/dots) to determine which is newer. It's an extremely reduced (in all regards, including functionality) version of StDoodle's thorough version string checker. The benefits are 1) it should circumvent those silly "Upgrade from 1.3 to 1.2" type messages, and b) it encourages the versioning standard used by actual applications and explained earlier by fronobulax.

It compares sections in order, and considers existing sections as newer than missing ones, i.e. 1.2.1 will show as newer than 1.2, 1.2.3.4 will be newer than 1.1.6, etc.
 

slyz

Developer
I changed the beginning of check_version() to this:
PHP:
   int[int] to_int( string[int] var ) {
      int [int] ret;
      foreach i, s in var {
         string temp; matcher m = create_matcher( "\\d", s );
         while ( m.find() ) { temp += m.group( 0 ); }
         ret[i] = temp.to_int();
      }
      return ret;
   }
   boolean sameornewer(string local, string server) {
      int[int] loc = split_string(local,"\\.").to_int();
      int[int] ser = split_string(server,"\\.").to_int();
      for i from 0 to max(count(loc)-1,count(ser)-1) {
         if (i+1 > count(loc)) return false; if (i+1 > count(ser)) return true;
         if (loc[i] < ser[i]) return false;
         if (loc[i] > ser[i]) return true;
      }
      return local == server;
   }

What it does is remove all non-numeric characters from "local" and "server", so the error shouldn't appear anymore.
 

zarqon

Well-known member
Update, Update, Update, Update the Function Library

Argh. There was a little but annoying problem with the new check_version() -- when you have a newer script than your stored property (from updating, usually), it skipped the comparison check. That was forgivable before, but now it's trying to be smarter about it, so I changed it. Updates for most scripts should now never require you to clear the _version_ property. Further, the update message includes a note about which property to clear in the decreasingly possible chance that you do get the message in error.

While I was at it, added the case-sensitive == operator for strings discussed previously in the SS thread -- equals(string, string), which was presented as a solution to this very issue by holatuwol a while back. It turned out to have a number of useful applications and its value in streamlining this workaround made we want to have it in ZLib.

I'm pretty OK with this being being the finished form of check_version(), though a few small tweaks may yet be possible. Warning messages for non-ints are fine in my book since they could very well annoy people into taking advantage of the new functionality, which would overall decrease user annoyance.

ZLib: Annoying Users Into Compliance Since 2009.

hahaha

Now hopefully I can get back to focusing on the combat scripts. Mine have been fixed for over a week now, I just haven't had time to document and post the updates.
 

Theraze

Active member
Any chance of integrating Veracity's suggested be_good function into zlib, or should I just put it into any script that uses items?
Code:
boolean be_good( item it )
{
  return my_path() != "Bees Hate You" || it.to_string().to_lower_case().index_of( "b" ) == -1;
}

Edit: Also, with this change, the in_mysticality_sign() from zlib's automcd should now be canadia_available().
 
Last edited:

zarqon

Well-known member
Looks good to me. oth of these have now een added to ZLi. (If this path doesn't have an effect on chat, it should.)

I haven't had time to play since the Bone Star exploded -- and when I have had a few moments, the lag made it fairly impossible given time constraints (not to mention, it somehow caused my login script to overdrink with more than 200 adventures remaining). All this to say, thanks for bringing those to my attention Theraze, since I still only have a vague idea what's going on with the revamp. From what I've read on the Wiki though, it looks like a really nifty change -- perhaps too nifty. I particularly like being able to upgrade softcore skills.
 
Top