ZLib -- Zarqon's useful function library

fronobulax

Developer
Staff member
You have no idea how much grief the (lack of) verbosity has caused me. It was at 0, for some reason.

BTW, with 0 verbosity, "zlib vars" prints nothing.

There has been some discussion of how verbosity inadvertently gets set to 0. It happens, and we may have figured out why, but there is no automatic fix. This does suggest, however, when trying to help someone with a problem that may involve zlib the first question should be to ask about verbosity. That might eliminate some red herrings in the future.
 

shazbot

Member
Maybe overkill, but perhaps a message the first time of day (when zlib checks itself?) to let the user know that verbosity is 0 and they won't be informed of any other zlib messages? You know, nip it before someone even has to post?
 

fronobulax

Developer
Staff member
Maybe overkill, but perhaps a message the first time of day (when zlib checks itself?) to let the user know that verbosity is 0 and they won't be informed of any other zlib messages? You know, nip it before someone even has to post?

The problem with that is verbosity of zero means STFU and checking that and confirming hardly qualifies. A better solution would be to change what zero means but that, of course, breaks a whole lot of working scripts.
 

zarqon

Well-known member
This bug was fixed epochs ago when Alhifar, with his eagle eyes and keen sense of smell, found and squashed it like a... bug. If people are still having that problem, they are using an absolutely obsolete version of ZLib.

Which there is only one excuse for: Ascend. dj_d removed version checking when he bundled my scripts, which has given me no end of grief. If people are still having the old "verbosity 0" problem with all of their ZLib-using scripts due to an ancient ZLib bundled with Ascend, in a way it makes Ascend a malicious script, doesn't it?

Anyway, I'm not going to do a thing about it -- I'm not responsible for dj_d's lack of updates.

EDIT: Okay -- I'll do something. I will make "zlib vars" print to the CLI no matter what. should help with debugging.
 
Last edited:

fronobulax

Developer
Staff member
Which there is only one excuse for: Ascend. dj_d removed version checking when he bundled my scripts, which has given me no end of grief. If people are still having the old "verbosity 0" problem with all of their ZLib-using scripts due to an ancient ZLib bundled with Ascend, in a way it makes Ascend a malicious script, doesn't it?
While my unoffical support for ascend is controversial enough that I am reconsidering just what and how much I do, I would respectfully report that my unoffical release of 2010_08_04 works with unmodified zlib. That feature has been retained in subsequent updates of mine so the only people who should have the experience you describe are those who have modified ascend themselves rather than starting with my modifications.

If you are still getting grief please refer the complainers to me.
 

Winterbay

Active member
EDIT: Okay -- I'll do something. I will make "zlib vars" print to the CLI no matter what. should help with debugging.

I think that would be a good idea. I mean even a person who has set his verbosity to 0 (in order to repress as much as possible) is probably going to want to see what his variables are if deliberately calling "zlib vars".
 

shazbot

Member
In my boat, it wasn't necessarily the version of zlib in ascend, as I had updated it for other reasons. But having a saved verbosity of 0 was the problem (running instance of mafia settings from 2009, so not too surprised)
 

zarqon

Well-known member
ZLib r25 Updates!

Three lovely new functions have made their way into the latest ZLib:

float isxpartof(item child, item ancestor)
Returns what percentage of an item a given ingredient is. For example, isxpartof(white pixel, digital key) returns 0.033333 (1/30th). However, isxpartof(red pixel, digital key) returns 0.03125 (1/32nd), not 1/90th, since it assumes the minimum amount of items needed (29 white pixels + 1 of each red/blue/green).

has_goal(item) now uses this new function, so if you're using SS, monsters dropping ingredients of goals will be considered for unsafe pickpocketing and goals Olfaction.

string join(string[int] pieces, string glue)
The opposite of split_string(), or the same as PHP's implode() -- joins all of the pieces of an array of strings together using glue. Useful for working with comma-delimited lists.

void load_kmail()
Uses KoL's server-friendly api.php to load your inbox (up to 100 kmails) into a global map of records named "mail". The records contains all the same info that KoL provides:

PHP:
record kmessage {
   int id;              // message id (you'll need this to delete the message)
   string type;         // possible values observed thus far: normal, giftshop
   int fromid;          // sender's playerid
   int azunixtime;      // unix timestamp of Arizona time
   string message;      // message (stripped of anything after the <center> tag)
   int[item] items;     // items included in the message
   int meat;            // meat included in the message
   string fromname;     // sender's playername
   string localtime;    // your local time according to your preferences, human-readable string
};
kmessage[int] mail;

Thus, ZLib makes it super easy for scripters to parse incoming kmail, since it also splits items and meat (safely) into their own fields. Just call load_kmail() in your script and all of your kmail will be readily available for foreaching.

There's also a new version of kmail() which accepts a kmessage as the parameter -- with the notable idiosyncrasy that it sends the mail to the name specified in "fromname".
 

Theraze

Active member
Question, doesn't this in has_goal:
Code:
   foreach m,r in rates if (r <= 0 || m == $monster[none]) remove rates[m];
make all the unspaded drops not work with the has_goal function again?

Edit: Also think this applies to that not working:
Code:
      res += has_goal(m)*(r + cradj/count(rates))/100.0;
Because while has_goal(m) will give a rate of .001, it then gets multiplied by r again, whic is 0. Unless the cradj/count(rates) turns it to a number greater than 0...

Eh, not really sure what's breaking it. But I know I can't use has_goal to find the best location for fraudwort anymore...
 
Last edited:

zarqon

Well-known member
Actually, has_goal(fraudwort) would give a result of 1.0 since is_goal(fraudwort) returns true -- and r in the code you quoted above is the monster appearance rate in the zone, not the item drop rate.

But I looked into it. The first problem is that has_goal(monster) excluded quest items from conditional drops. Why? I can't remember. Probably because you only get them once, and after that they can't drop again. But, since they would probably only be goals when you can actually get them, I'll un-exclude them. This code has been in place basically since the function was introduced, by the way -- not just since this last ZLib update, so I don't know what you mean by "anymore".

However, even after re-including conditional quest items, with a goal of fraudwort has_goal(demoninja) still returned 0. So I put a lower cap on all item drop rates of 0.001, prior to adding the item drop bonus. I'm pretty confident this is lower than the lowest drop rate in the game, so it won't harm anything, and it still allows results of 0 or less with negative item drop modifiers.

Now I get this:

> goalinfo

fraudwort is 1 of a goal.
Encountering Demoninja: 0.0%
Adventuring at Dark Elbow of the Woods: 0.0%
Adventuring at Pandamonium Slums: 0.0%
finished!

Better!

I updated the first post, but didn't feel this change merited a version bump. We'll consider it part of the next update.
 

fronobulax

Developer
Staff member
I updated the first post, but didn't feel this change merited a version bump. We'll consider it part of the next update.

Since my job title currently is "Configuration Manager" I am amused that you think version numbers are so important that they cannot be changed for "little things" and saddened that you have so little respect for best practices that you would release a change and not change the identifier. Good thing KoL is not a profession for us. ;-)
 
Last edited:

zarqon

Well-known member
Well, here are my options:

  1. Don't update the script, annoying people who would like their specific problem fixed quickly.
  2. Update the script and change the version number, annoying all the users who don't benefit from the added functionality (most people, in this case).
  3. Update the script, but don't change the version number, annoying anyone not in either of the above groups.
  4. Change the version number but don't actually update the script, annoying everyone!

I want to annoy as few people as possible, so I usually estimate the size of these user groups, based on 1) whether or not all users need the update, II) whether not downloading the change could be problematic for users who don't update, c) whether the change will fix or enhance known scripts depending on these functions, and 사) how many downloads have occurred so far. Then I choose the option that I believe will annoy the smallest group. My decision is based not on how "little" the change is, it's based on how big the "annoyed user" group is.

One of these days I'm going to say "screw it" and choose option 4, just for fun. :D
 

StDoodle

Minion
Option 5; use that version-checking function of mine, and only notify users in check_version() for "major" changes etc. ;)
 

Theraze

Active member
Thanks zarqon. :) I saw this was a c0 (though it's been spaded since as c50) drop, and thought that the 0-ness was why it was failing, not the c-ness. Thanks for fixing anyways though. :)
 

fronobulax

Developer
Staff member
I want to annoy as few people as possible

Which is a fine and noble goal and you are achieving it admirably since I am amused, not annoyed. I was just stepping back and noting the real function of version numbers, which is to uniquely identify something. Different code with the same identifier might not cause any problems but when it does the annoyance factor will hit the roof.
 

StDoodle

Minion
Indeed. Constant updates can become a teeny bit annoying, true. But nothing compares to getting stuck when you "know" you have the current version, because your version numbers match -- and yet something isn't working as it should. Then, it turns out that the problem was a non-updated version number. Argh!

Also, one of the original goals of my comparison function was to allow users to set their own notification threshold. But that relies on either a stricter standardization of version schemes or someone to come up with a clever idea that has thus far eluded me.
 

Rinn

Developer
Could you make the update link in the cli clickable instead of having to copy and paste it
 

Theraze

Active member
It's already using print_html and a href... if it's not clickable, either mafia uses a different html parser for links or...?
 

slyz

Developer
The href is in the return value (for use by relay scripts).
You can have a clickable link in the gCLI by changing line 186 to:
PHP:
vprint_html("Upgrade "+soft+" from "+thisver+" to "+get_property("_version_"+prop)+" here: <a href='http://kolmafia.us/showthread.php?t="+thread+"' target='_blank'>http://kolmafia.us/showthread.php?t="+thread+"</a>",1);wait(1+w);
 
Top