ZLib -- Zarqon's useful function library

I'm made more or less the same change you did. What I meant was to replace
PHP:
"http://kolmafia.us/showthread.php?t="+thread
by
PHP:
"<a HREF='http://kolmafia.us/showthread.php?t="+thread+"'>http://kolmafia.us/showthread.php?t="+thread+"</a>"
 
Update!

Added rnum(), which converts an int or float into a human-readable string. I recommend that you always use this in place of to_string() for ints and floats, especially if you foresee needing to print large values.

By default it will round floats at the hundredths place, but you can specify the place at which to round as an optional second parameter.

PHP:
rnum(-1000000000) => "-1,000,000,000"
rnum(0.577215665) => "0.58"
rnum(0.577215665,4) => "0.5772"
rnum(3.0) => "3"
rnum(9999.9999) => "10,000"
rnum(1234.5678,1) => "1234.6"

Also, I've concluded that the new relay script functionality makes the WOSSMAN no longer ideal, so I've removed all the commented-out code for that. Expect a very nifty relay ZLib settings editor sometime in the not-too-terribly-distant future.
 
Houston Syndrome

SOLVED BY UPDATE

Love the scripts; which are interactively delightful.

Sadly it seems although zlib or one of its friends is giving me the severe case of the countdowns.

Code:
Countdown: 3 seconds...
Countdown: 2 seconds...
Countdown: 1 second...
Waiting completed.

Request 1 of 245 (Woods: Friar's Gate) in progress...

[2259] Friar's Gate
Encounter: Hellion
Strategy: /home/zacius/.kolmafia/ccs/default.ccs [default]
Round 0: zacius loses initiative!
You lose 5 hit points
Countdown: 3 seconds...
Countdown: 2 seconds...
Countdown: 1 second...
Waiting completed.
Countdown: 3 seconds...
Countdown: 2 seconds...
Countdown: 1 second...
Waiting completed.
Countdown: 3 seconds...
Countdown: 2 seconds...
Countdown: 1 second...
Waiting completed.
Round 1: zacius attacks!

My CCS is:
1: consult SmartStasis.ash
2: attack with weapon

I am running BBB, SS, FTF and Bale's UR.

Initially I suspected a datafile would have a variable I could switch around, but after a quick read through the data directory, then the *.ash files I was using I was at a loss.

Removing the scripts from the folder removes the countdown, but why run mafia without such marvelous scripts?

Thank you in advance.
 
Last edited:
BatMan has revealed a glitch in the new rnum() -- I carelessly used floor() where I should have used truncate(), so for negative floats it would erroneously lower the integer portion. Uploaded a fix but didn't change version number, since it's not that big a deal and I don't want to cause more countdown-induced angst.

@zacius: do you have your verbosity set to 0? Setting it higher would have given you a clue what was going on.
 
Recursive item checking

Hey Zarqon, I've noticed a problem using FTF, which i managed to track down to has_goal in zlib.
Most likely it's because i have done something that cocked it up, but anyway thought i'd mention it.

Basically when fighting inside the knob kitchens:
-FTF calls set_autoputtifaction()
-inside set_autoputtifaction() it calls has_goal() on every monster from the zone
-when has_goal() is called on the knob goblin chef, has_goal() is called on each drop of the chef
-when has_goal() is called on the wad of dough the chef drops, has_goal() is called on everything from use_for_items map for wad of dough, which is flat dough.

You've probably seen where this is going now, has_goal calls itself on wad of dough, which causes it to call on flat dough, which causes it to call on wad of dough etc. This repeats until mafia complains and prints a debug log.

Not sure if there any other recursive things in the use_for_items map that might cause this.

Do other people experience this? I'm using the latest mafia, zlib, smartstasis and ftf.
 
That would explain why I got an exception when I had a spooky putty sheet, and didn't get an exception when I had a spooky putty monster instead ... as long as this code is only called when puttying is possible.
(of course, I might have misremembered *again*)
 
@twistedmage1: Good catch, and thanks for your effort in tracking down the problem. It seems that FTF/SS are going through a lot of changes lately, so I'll wait to fix this until the next update, which will probably be soon.
 
When looking recursively at ingredients for craftable items in FamiliarFeeder, I ran into this kind of problem. From what I gathered, the only circular items are clovers, dough, and the charrrms. Hardcoding them in is possible, or using a "currently_considering" map à la PriceAdvisor would work for has_goal().
 
Thanks for that, slyz. I'll probably hardcode exceptions in this case.

And while I'm at it, the new item_drops_array() allows me to do what I had originally intended:

float has_goal( item )
float has_goal( monster )
float has_goal( location )


In each case, the return value would be the likelihood that encountering the item/monster/location once would result in a goal.

How many people are using the has_goal(monster) with the boolean return value, and of those people, who objects to so changing it?
 
Even if someone wants to use the boolean version, it would be very simple to use to_boolean( has_goal() ) for the same purpose.
 
The point is, changing this would cause scripts that use the current has_goal(monster) to error out before version checking. I wanted to get an estimate of the fallout if I change it.
 
Yeah, my point was that people can update the scripts with only a tiny edit when they post to ask why it doesn't work anymore. It's an easy enough fix to be worth the great advantage you're adding.
 
Why not just add a new function name, goal_odds() or something, and change has_goal() to simply return the boolean conversion of it?
 
Ok, Let me rephrase the question into a request:

Script authors, please let me know if you are using ZLib's has_goal(monster), because I'm planning on changing the return value type. If you are using the function, I'd like your opinion about how to handle the transition. Would you prefer something transitional, as StDoodle has suggested, or a direct change, perhaps timed conveniently for you? If no one is using it, I'll just change it and not worry about fallout.
 
I use it in my betweenBattleMood and I'm happy adding to_boolean() for that purpose. Feel free to make the change without worrying about my usage of has_goal().
 
Just a quick question -- by "returns the likelihood", do you mean as a percent, or as a decimal (at most 1)? I'm asking this because if the second one is the case, then to_boolean() will return false unless it's a guaranteed drop (adding ceil() would be necessary, I believe).
 
1.0 >= result >= 0.0

Returning percents nearly always means dividing by 100 in use -- a bit of an annoyance.
 
Okay. Because of the way to_boolean() works...
Code:
> ash .9.to_boolean()

Returned: false

> ash .9.ceil().to_boolean()

Returned: true

Just a heads up to anyone (namely Bale, so far) who'd use the to_boolean() fix.
 
Back
Top