ZLib -- Zarqon's useful function library

zarqon

Well-known member
Hahahahaha I believe I need to add that function to ZLib.

And come on Bale, are you seriously saying you never thought that about that particular function name before?
 

eegee

Member
As of build r10052 all calls to
Code:
numeric_modifier("_spec","<anything>")
seem to be breaking silently.


For example
Code:
numeric_modifier("Item Drop")
works but
Code:
numeric_modifier("_spec","Item Drop")
doesn't.

EDIT: on second thought, this is actually more of a problem with KoLmafia than zlib
 
Last edited:

Donavin69

Member
in the my_defstat() function, the use of the numeric_modifier("_spec","<stat>") is returning the wrong values.

I've modified it in my version to use the my_buffedstat($stat[<stat>]) and it works ok.

i.e. print( numeric_modifier("_spec","moxie"));
print(my_buffedstat($stat[moxie]));
0
424

on one char, on another
304
408
 

jasonharper

Developer
print( numeric_modifier("_spec","moxie"));
print(my_buffedstat($stat[moxie]));

Those two calls aren't doing even vaguely the same thing. The "moxie" numeric modifier is merely your additive bonuses, not including percentage bonuses (that would be "moxie percent") or your base moxie (which isn't a modifier at all). "Buffed Moxie" is the modifier that predicts what my_buffedstat() would return.
 

Donavin69

Member
Isn't the goal of my_defstat() to return the actual result of the defensive stat? Which would be the complete my_buffedstat(), not just the additive bonuses.
 

slyz

Developer
Zlib's my_defstat() correctly uses
PHP:
numeric_modifier("_spec","Buffed Moxie")
I don't see any problems with _spec:
Code:
> ash my_buffedstat( $stat[ moxie ] )

Returned: 165

> ash numeric_modifier( "_spec", "Buffed Moxie" )

Returned: 165.0

> whatif up superhuman sarcasm

Moxie Percent 100.0 (+100.0)
Buffed Moxie 330.0 (+165.0)

> ash numeric_modifier( "_spec", "Buffed Moxie" )

Returned: 330.0
 

zarqon

Well-known member
The issue that eegee and Donavin are reporting here is that after logging in, if mafia has not yet speculated anything, _spec will return 0 for all your stats. With the new ZLib change my bounty script was refusing all bounty options since my defense was apparently 0. You have to call an empty "whatif" first to get it to see your stats correctly.

If this is deemed "Not a Bug" I'll add a check to call "whatif" in my_defstat() if mafia thinks it's 0, but it would be nicer if _spec worked even without having speculated.

@eegee, Donavin: as a workaround you can add a call to "whatif" (with no parameters) at the top of your login script.
 
Last edited:

eegee

Member
Thanks zarqon for narrowing down the problem I was having.

I can confirm that after a fresh opening of mafia, "_spec" would return 0.0 for anything until "whatif" was called at least once. I've gone and added "whatif" to my login script for now.
 

jasonharper

Developer
Not a bug. _spec exists for the sole purpose of determining the results of a speculative action; using it in any way, without having speculated about anything, is fundamentally meaningless.
 

zarqon

Well-known member
Ok, then any script which wants to be transparent to speculative values needs to make a parameter-less speculation to "initialize" _spec before accessing the values. I'll just do that top-level in ZLib, and at least ZLib-powered scripts won't run across this problem again.

Updated, r33!

I'm checking numeric_modifier("_spec","Buffed Muscle") == 0 to determine whether or not to "initialize" _spec, so it should only happen the very first time you run ZLib in a session.
 

Bale

Minion
Haw?!

What I don't get is why you use "_spec" at all! Won't that work just fine without it? And it could cause trouble!

What if someone uses "whatif outfit frat warrior" early in the session that has nothing to do with a call to my_defstat() later? It will return the frat warrior outfit stats, not the current outfit.

What if your "Buffed Muscle" and "Buffed Moxie" change? Because you used "_spec", my_defstat() will return the value from the beginning of your session, not the current values!

These are reasons that your use of "_spec" is a bug, not the lack of an initial value. You're only making things worse by putting in a spurious call to whatif just to conceal the problem. That's like putting all your trash in the closet instead of cleaning a room.
 
Last edited:

zarqon

Well-known member
Ah right -- it should clear speculation every time then. Hasn't been a problem for me since BatBrain speculates every combat round anyway.

I want to use speculative values, quite simply, to make certain ZLib functions useful within a speculative context (such as BatBrain) as well as without.

EDIT: Ok, if you are one of the 3 users who downloaded r33 before this edit, redownload it.
 
Last edited:

Donavin69

Member
Thanks for the update, I didn't understand what the _spec was. Does it need to be 'refreshed' each time you use it?
 

Theraze

Active member
Just wanted to say that it seems so sad that zlib posts this every round of combat when the script gets updated between play periods...
Request 5 of 49 (Mountain: Barrel full of Barrels) in progress...

[373] Barrel Full of Barrels
Encounter: Barrel Smash
You acquire an item: salty dog

The string "r33" is not an integer; returning 33 (zlib.ash, line 191)
The string "r32" is not an integer; returning 32 (zlib.ash, line 191)
The string "r33" is not an integer; returning 33 (zlib.ash, line 192)
The string "r32" is not an integer; returning 32 (zlib.ash, line 192)

Request 6 of 49 (Mountain: Barrel full of Barrels) in progress...

[374] Barrel Full of Barrels
Encounter: Barrel Smash
You acquire an item: tequila sunrise

The string "r33" is not an integer; returning 33 (zlib.ash, line 191)
The string "r32" is not an integer; returning 32 (zlib.ash, line 191)
The string "r33" is not an integer; returning 33 (zlib.ash, line 192)
The string "r32" is not an integer; returning 32 (zlib.ash, line 192)

Request 7 of 49 (Mountain: Barrel full of Barrels) in progress...

[375] Barrel Full of Barrels
Encounter: Barrel Smash
You acquire an item: bottle of vodka
Before every single fight, as well as during every combat... ah well. :)
 
Top