Feature - Implemented Add effect() text function to modifier_eval()

zarqon

Well-known member
There are starting to be quite a lot of places where I need to access the remaining turns (or presence) of an effect in a formula. Adding a text function (similar to the existing loc(), pref(), etc.) for the amount of turns you have of an effect would allow me to significantly reduce the number of variables I need to pass in to ZLib's eval() function -- which replaces string keys in the formula with float values before calling modifier_eval() on it. This would make my script both smaller and more efficient.

It might be easier to require the number of the effect as the function's parameter, rather than the actual name of the effect, since the effect name might contain parentheses. Or, it could allow both if doing matching on the effect name wouldn't cause trouble, but I suspect simple integers would be easier and safer.

This enhancement could only become more useful as time goes by!
 
Time has indeed gone by, and as I mentioned, the proposed enhancement has become even more useful! Bumping.
 
z, you aren't by chance looking for have_effect(), which rather than returning a boolean, actually returns the int number of turns you have left of said effect is... are you?

Edit: I'm a moron, you're looking for support specifically in eval() types... doh. That's what I get for reading these forums at 3am... :p
 
Last edited:
Basically. have_effect() is an ASH function. I'm looking for an equivalent function for use within modifier_eval() formulas. For example:

PHP:
// candy kneecapping stick damage (17 is Sugar Rush)
modifier_eval("15+10*max(1,effect(17))");

// parasitic headgnawer retaliation damage (580 is Yuletide Mutations)
modifier_eval("min(L,15)*(1+max(1,effect(580)))*2.5");

EDIT: Haha, ninja'd by yourself.
 
r10930
Code:
> ash modifier_eval("effect(sugar rush)");

Returned: 10.0

> ash modifier_eval("15+10*max(1,effect(sugar rush))");

Returned: 115.0

EDIT:

seems interesting. I'll take a stab at it, if no one else starts working on it from the bump.
If you find something you would have done differently/more efficiently, please point it out. I'm not sure I understand everything in Expression.java.
 
Fabulous, thanks slyz! One question as I begin to take advantage of this change: does the limitation of only one text function per expression still apply, or has that been changed?
 
I don't think so?
Code:
> ash modifier_eval("effect(butt rock hair)");

Returned: 10.0

> ash modifier_eval("mainhand(axe)");

Returned: 1.0

> ash modifier_eval("effect(butt rock hair)+mainhand(axe)");

Returned: 11.0

EDIT:
Oh, I just saw the following note in modifiers.txt:
Code:
# There can be at most one of each text function in any single expression.
I don't think this is true anymore:
Code:
> ash modifier_eval("effect(go tiger)");

Returned: 16.0

> ash modifier_eval("effect(song of accompaniment)");

Returned: 40.0

> ash modifier_eval("effect(song of accompaniment)+effect(go tiger)");

Returned: 56.0
 
Last edited:
Awesome, thanks again slyz! For the win, indeed.

Should probably add this new handiness to the Wiki page for modifier_eval(). I also realized I should have checked there for the answer to my question first, evidently the 1-per-expression limitation was removed many moons ago.
 
Last edited:
Back
Top