MV Battle Formula Help

Thanks in advance for any help. 


I usually like to figure these things out, but I'm not used to the MV scripting and don't know what is wrong. I've tried changing the :'s and ;'s around, using "if", adding/subtracting else, but nothing has done what I want this to. 


Here is the formula I most recently tried: if (!b.isStateAffected(24)) b.addState(25); a.atk * 4 - b.def * 2: else; if (!b.isStateAffected(25)) b.addState(26); a.atk * 4 - b.def * 2: else; if (!b.isStateAffected(26)) b.addState(27); a.atk * 4 - b.def * 2


Since I can't get a stacking state plugin to work I am trying to have the attack do normal damage with each hit and "stack" a state. Each state is (in my eyes) the same until it hits the fourth stack when it changes to a new state. So, 1st attack - applies state 24, 2nd attack - applies state 25, 3rd attack - applies state 26, 4th attack - applies state 27.


Right now, the state never changes from the first state, and the damage is always 0.
That's because your damage formula has syntax errors.


Specifically:


1. The if clause ends with b.addState(25), because it's not immediately followed by else/else if, but rather a.atk * 4 - b.def * 2. This lead to unexpected token else.


2. : isn't supposed to be used this way, leading to unexpected token :.


Showing that in multiline should make it much more crystal clear and obvious:


if (!b.isStateAffected(24)) b.addState(25);
a.atk * 4 - b.def * 2:
else; if (!b.isStateAffected(25)) b.addState(26);
a.atk * 4 - b.def * 2:
else; if (!b.isStateAffected(26)) b.addState(27);
a.atk * 4 - b.def * 2


To fix the syntax errors, you can change the above to this:


if (!b.isStateAffected(24)) b.addState(25);
else if (!b.isStateAffected(25)) b.addState(26);
else if (!b.isStateAffected(26)) b.addState(27);
a.atk * 4 - b.def * 2


Which is the same as this in 1 line:


if (!b.isStateAffected(24)) b.addState(25); else if (!b.isStateAffected(25)) b.addState(26); else if (!b.isStateAffected(26)) b.addState(27); a.atk * 4 - b.def * 2




P.S.:


1. Whenever a damage formula unexpectedly returns 0, you should suspect that those javascript have failed to execute.


2. I guess this javascript syntax checker can be useful here 🙂

Original thread: https://forums.rpgmakerweb.com/threads/mv-battle-formula-help.67086/