Is adding states in damage formula's broken?

First off, I tried:


a.mdf >= (Math.randomInt(20) + 1 + b.luk) ? 4 + b.addState(14) : 4

this works if i just have numbers and no state, otherwise this returns 0 for me

I tried using b.addstate(14), and it did not apply state. I tried b.addstate(14); 100 and it gave me damage, but no state
Are you trying to apply the state to the actor or the enemy that is targeted?

If your trying to add it to the enemy then why not use the Effects, Add state option?

This is one will add the state to the actor (user) then deal damage to the enemy.
a.addState(29); a.atk * 1.2 - b.def
The damage formulas are designed only to read a value, not to do anything. While it might be possible to do something as you wish, misuse of a functionality is never a good way.
The damage formulas are designed only to read a value, not to do anything. While it might be possible to do something as you wish, misuse of a functionality is never a good way.
oh, so it wont work at all? I thought that it said so in the damage formula tutorial?
Are you trying to apply the state to the actor or the enemy that is targeted?

If your trying to add it to the enemy then why not use the Effects, Add state option?

This is one will add the state to the actor (user) then deal damage to the enemy.
a.addState(29); a.atk * 1.2 - b.def
yes, in my formula i wrote b.addState(14)
4 + b.addState(14)
this is your mistake - addstate is a function, not a number and as such cannot be added in a mathematical formula.
it needs to be used as a command by itself.

additionally, the damage formula needs to return a value, so commands cannot be the last thing in there.

untested, but this should work:

(a.mdf >= (Math.randomInt(20) + 1 + b.luk)) ? {b.addState(14); 4} : 4
If your trying to add it to the enemy then why not use the Effects, Add state option?
Because that will cause the effect to fire off with certainty (or whatever percent chance that's given), while OP wants to have it happen based on the attacker's mdf, judging by the formula he posted.
The conditional operator condition ? ifTrue : ifFalse is only for single-statement operands. For multiple statements, use a full if (condition) { ifTrue } else { ifFalse } block, e.g.

if (a.mdf >= Math.randomInt(20) + 1 + b.luk) { b.addState(14); 4 } else { 4 }
Since the result is always 4, though, this can be simplified:

if (a.mdf >= Math.randomInt(20) + 1 + b.luk) { b.addState(14); } 4

Note: if an actor with the Autobattle trait has this skill, the formula will be evaluated whenever they consider using it. This is one reason the skill formula box should generally only be used to calculate the damage/heal value, rather than do things (e.g. apply a state).

[Edit: corrected a.addState -> b.addState.]
this is your mistake - addstate is a function, not a number and as such cannot be added in a mathematical formula.
it needs to be used as a command by itself.

additionally, the damage formula needs to return a value, so commands cannot be the last thing in there.

untested, but this should work:

(a.mdf >= (Math.randomInt(20) + 1 + b.luk)) ? {b.addState(14); 4} : 4

i tried this and it returned 0, i used this bit only {b.addState(14); 4}, but it just deals 4 damage and won't apply state
The conditional operator condition ? ifTrue : ifFalse is only for single-statement operands. For multiple statements, use a full if (condition) { ifTrue } else { ifFalse } block, e.g.

if (a.mdf >= Math.randomInt(20) + 1 + b.luk) { b.addState(14); 4 } else { 4 }

Since the result is always 4, though, this can be simplified:

if (a.mdf >= Math.randomInt(20) + 1 + b.luk) { b.addState(14); } 4


Note: if an actor with the Autobattle trait has this skill, the formula will be evaluated whenever they consider using it. This is one reason the skill formula box should generally only be used to calculate the damage/heal value, rather than do things (e.g. apply a state).

[Edit: corrected a.addState -> b.addState.]
you are a beautiful person thank you so much this worked. <3
Great! Happy RPG Making~ 😂
When looking to use more than one expression statement in a ternary, you need to separate them by commas and enclose it with parentheses (it evaluates the expressions from left to right and only returns what is on the right side of what is in the parentheses):
JavaScript:
a.mdf >= (Math.randomInt(20) + 1 + b.luk) ? (b.addState(14), 4) : 4

As @caethyril pointed out, the if-statement will work best here, especially since you have the same value for damage regardless of the condition. And definitely auto-battle issues - I don't use them but as many have stated, there are possible issues with evaluating other things besides damage value.

When using curly brackets, you'll need to define a const function expression first and allow it to return a value in order to use it - this one is very verbose and you might as well avoid it or write a function, save it as a plugin, and call that instead:
JavaScript:
const exp = () => {b.addState(14); return 4}; a.mdf >= (Math.randomInt(20) + 1 + b.luk) ? exp() : 4

Original thread: https://forums.rpgmakerweb.com/threads/is-adding-states-in-damage-formulas-broken.170466/