ZLib -- Zarqon's useful function library

Don't replace them! I treasure them.

Today's Updates

I'd forgotten (due to not being able to see it on my small screen) that I was supposed to update those sign changes Theraze pointed out a while back. So, I've posted that update, and as a bonus it also contains another friggin' nifty little function which I am pleased to introduce:

void process_kmail(string functionname)
Loads your kmail, then calls the function specified by functionname on each message. That function must be top level, accept a kmessage as its parameter, and return a boolean. The return value specifies whether or not to delete the message afterwards. When all kmails have been parsed by the supplied function, all messages for which the function returned true will be deleted.

It's lovely! Here's a simple example which deletes all kmails from your pen pal:

PHP:
boolean deletepenpal(kmessage m) {
   return (m.fromname == "Your Pen Pal");
}
process_kmail("deletepenpal");

My Registry script, login script, and StashBot script are getting smaller and smaller. w00th!

(The T9 on my phone recommended "w00th" as an option once when I started typing "w00t" -- I'm trying to make it catch on because it's kind of HILARIOUS.)
 
I've started getting an error message after every adventure:

Bad item value: "book of pirate insults" (zlib.ash, line 465)

I'm in a Bees Hate You HC run, so I don't have access to the Book of Pirate Insults. I'm running the latest mafia (r9509) and zlib.

Doing a brief glance through at that point in the file, I wouldn't think it would even reach that point in that line since it checks first if my_location() == $location[barrr], and I haven't adventured in the barrr all day. I've confirmed that my_location isn't bugging out for me and is indeed displaying my correct location.

Everything else seems to be working fine, just getting the error message.
 
I could be mis-remembering, but I'm pretty sure any "bad" type will generate that message when a script attempts to run, whether the code would get there or not.

Does mafia internally switch out the two insult books, causing it to only recognize one of the two as a valid item? I honestly have no clue, but if that's the case, zlib and other scripts could get around this by using a string setting for the item name, which was set based on my_path(), and then cast the resulting string as the item needed.
 
StDoodle, both items are valid regardless of path.

The entire script is checked for errors such as bad item values before it ever attempts to run.

Isvarka, sometimes I have gotten bad item values when the name of the item required fuzzy matching. Restarting mafia always fixed that problem. The proper name for the item is "The Big Book of Pirate Insults". This is the only cause of the problem I could think of, but if you are still getting the error then I have no idea.
 
Yeah, it wasn't occurring when I was running my turns this morning, so I'm guessing Mafia just needed a restart.

Thanks.
 
I would like to ask for a one character change to the next version of zlib. I went crazy trying to debug a very simple script because load_kmail() parsed my message in a non-intuitive manner.

Please change line 555 from: mail[n].message = mbits.group(1);
to: mail[n].message = mbits.group(0);

I'll give you an example of why:

Code:
  9 => 
  array (
    'id' => '106615241',
    'type' => 'normal',
    'fromid' => '2208837',
    'azunixtime' => '1308979462',
    'message' => '<center><img src=http://images.kingdomofloathing.com/adventureimages/timesarrow.gif width=100 height=100 alt="Time\'s Arrow" title="Time\'s Arrow"><br><b>arrowbot</b> has shot you with a time\'s arrow.</center><center><table><tr><td><img src="http://images.kingdomofloathing.com/itemimages/hourglass.gif" height=30 width=30 alt="Adventures"></td><td valign=center>You gain 5 Adventures.</td></tr></table></center>',
    'fromname' => 'arrowbot',
    'localtime' => '06/25/11 01:24:22 AM',
  ),

Here's another example:

Code:
  26 => 
  array (
    'id' => '106450105',
    'type' => 'normal',
    'fromid' => '131848',
    'azunixtime' => '1308295636',
    'message' => '<center><table cellpadding=0 cellspacing=0><tr><td colspan=3 width=162 height=25><img src="http://images.kingdomofloathing.com/otherimages/heart/hearttop.gif" width=162 height=25></td></tr><tr><td width=31 height=50><img src="http://images.kingdomofloathing.com/otherimages/heart/heartleft.gif" width=31 height=50></td><td width=100 height=50><Table cellpadding=0 cellspacing=0><tr><td width=100 align=center><img src="http://images.kingdomofloathing.com/otherimages/letters/i.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/t.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/s.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/space.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/a.gif" width=20 height=20></td></tr><tr><td height=10></td></tr><tr><td width=100 align=center><img src="http://images.kingdomofloathing.com/otherimages/letters/t.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/r.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/a.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/p.gif" width=20 height=20><img src="http://images.kingdomofloathing.com/otherimages/letters/exclamation.gif" width=20 height=20></td></tr></table></td><td width=31 height=50><img src="http://images.kingdomofloathing.com/otherimages/heart/heartright.gif" width=31 height=50></td></tr><tr><td colspan=3 width=162 height=52><img src="http://images.kingdomofloathing.com/otherimages/heart/heartbottom.gif" width=162 height=52></td></tr></table></center><center><table class="item" style="float: none" rel="id=2306&s=5&q=0&d=1&g=0&t=1&n=1&m=1&p=0&u=a&ou=send"><tr><td><img src="http://images.kingdomofloathing.com/itemimages/candyheart.gif" alt="orange candy heart" title="orange candy heart" class=hand onClick=\'descitem(451194816)\'></td><td valign=center class=effect>You acquire an item: <b>orange candy heart</b></td></tr></table></center>',
    'fromname' => 'Pyren',
    'localtime' => '06/17/11 03:27:16 AM',
  ),

In short, sometimes it is nice to be able to parse the html sections of messages that give you candy hearts, bricks, or 5 adventures. (The last one is weird.) I made the change to my local copy of zlib, but I'm hoping that I won't need to alter the next official update of zlib whenever you release it.
 
The URL needed to delete kmails changed slightly. Line 571 of zlib
PHP:
foreach k in processed del += "&sel"+k+"=checked";
should be changed to:
PHP:
foreach k in processed del += "&sel"+k+"=on";
 
I don't know what I'm doing wrong, but for some reason, typing "zlib vars" just gives me

Expected ), found ? (zlib.ash, line 169)

What should I do?

(Much thanks)
 
Try with a fresh download of Zlib would be my guess.

EDIT: Also make sure you don't have another zlib.ash in a subdirectory of Mafia's /scripts folder.
 
Also, check what version of mafia you're using... if you haven't updated to the latest daily build recently, your mafia may not be able to handle ternary operators (condition ? iftrue : iffalse) and it would get that sort of error message...
 
Lessee... there's a ternary operator on that line, which was added to KoLmafia in revision 8947 on January 26, 2011 which was incorporated into release 14.4 on February 2, 2011.

I think you should run a newer version of KoLmafia.

I am sure I am going to be ninja'd on this, but I bet they didn't give you revision numbers and dates. :)
 
Believe I've finally figured out why has_goal keeps shooting me off in random directions... bounties. Since I like to occasionally keep an active bounty around for if I have turns to burn, or so I can get 2 bounties on the day I break the crystal, this massively confuses zlib's has_goal function which considers any bounty item as a valid goal location. Any chance we could get a version of has_goal that skips bounty items? A zlib variable to disable the bounty checking on goals would work as well and would probably be easier to implement...

I'd just prefer not to have to mangle my zlib more than I have to in ways that aren't officially supported. :)
 
One more note... I believe that it's the Hippy Camp in Disguise and Frat House in Disguise that the wiki names as On the Verge of War. The map manager's turtles.txt believes that the advanced turtles should be available here, but I keep getting more and more hedgeturtles... this is sad. :) Mostly because I get excited for another grinning or syncopated turtle and instead have... well, currently 5 hedgeturtles, plus my shield. Tried to upload a version with these properly set, but it doesn't appear to have gone. Probably just doing it wrong.
 
r29 Updates!

Nothing super exciting, but nothing exciting came along for ZLib and it has been quite a while now since Veracity added the coinmaster type to ASH, which ZLib ought to support in script settings.

Besides adding the $coinmaster[] type to setvar() and normalized(), there were a few other little tweaklets to kmail processing:

  • Only strip the HTML bits from the message field of kmails if meat/items were parsed from it. Otherwise, leave it for scripters to handle themselves.
  • If process_kmail() is called several times, don't parse kmails which were deleted the previous round.
  • @slyz: Evidently the URL for deleting kmail works either way, but since your way was shorter I changed it. :)


@Theraze: has_goal() does not consider all bounty items goals, only your current one. I'm not clear on what you want me to change, so I didn't change anything... yet.
 
r29 Updates!

@Theraze: has_goal() does not consider all bounty items goals, only your current one. I'm not clear on what you want me to change, so I didn't change anything... yet.

If you have a specific goal set, do not consider looking for your bounty as of equal validity as your desired goal. Doesn't appear to be a good way to see if you have any current goals set though. Unless you do another full item search to check if you have bounty items or not. The benefit of this would be that if you don't have goals set, the "best bounty location" check should be FAST. Since it doesn't have to worry about the slow isxpart or any of that... but this appears to be a current limitation... though it's a fast check. 2-3 milliseconds according to this:
> ashq int time; time = gametime_to_int(); foreach it in $items[] if (is_goal(it)) print_html("Goal set."); print_html(gametime_to_int()-time);

Goal set.
2

> ashq int time; time = gametime_to_int(); foreach it in $items[] if (is_goal(it)) print_html("Goal set."); print_html(gametime_to_int()-time);

Goal set.
3
But yeah... since that's relatively fast, if it would be possible to do a quick check first to see if goals are set and if so, skip the bounty checking. If not, just check for current bounties, if one exists. I might try to work out the code for that today, if I end up staring at computers too long. :)
 
@Weatherboy: the Xenomorph must not be in the data file.

@Theraze: Aha, I think I got it. You are using has_goal(location) to automate goal fulfillment, and if you have an open bounty hunt this throws off your location selection algorithm, which I assume to be a foreach of locations, skipping !can_adv(loc,false) and choosing the one with the highest has_goal(loc).

Looking forward, I believe your location selection algorithm will be very easy to fix once bounty information is added to proxy records, without any changes to has_goal(). In your foreach of all locations, you'll be able to ignore the bounty location or substitute 0.0001 for the has_goal() result or somesuch, a la valuetocheck = (loc.bountyitem == get_property(currentBountyItem) ? 0.0001 : has_goal(loc));

However, the proxy record feature requests haven't shown any signs lately of being added to mafia and it also wouldn't be too difficult to add an overloaded has_goal() with a second boolean parameter to skip bounty items. Will have to think about it. Prod me later if I have thought too long on it.
 
Back
Top