Is my formula good?

I made this damage formula for a skill in RPGMakerMV that should add a state is the state doesn't already apply, or attack normally and remove the state if the state already apply.


"if (a.isStateAffected(13)) {a.remove_state(13); a.atk * 4 - b.def * 2} else {a.addState(13); 0};"


Only the "else" part that should add the state seem to work. If the state already applies, the attack will deal 0 damage no matter what the damage calculation is in any part.


Please help.
you're getting one thing wong, the last value (the one to be returned) is what should be numeric.


so your formula should be something like


var result = 0; if (condtion) {removeState; result = X} else {addState; result = Y); result
Oh! I've actually made an attack kinda sorta like this!


b.isStateAffected(10)? (a.atk + a.mat) * 0.4 : b.addState(10)


While my skill is seeing if the target is affected by the state (in this case, my poison state), it deals a lot of damage (for my game.) If the target is not poisoned, it is now. :3


To change it to your skill, we would do this:


a.isStateAffected(13)? (a.remove_state(13) ; a.atk * 4 - b.def * 2) : a.addState(13)


This is asking "Is the user effected by State 13? If so, remove the state and deal (a.atk * 4 - b.def * 2) damage to the target. If not (Else), then apply State 13 to the user."


In honesty, you don't need to add the "; 0" to your else statement. If you don't have it, it can't do anything, and this way shouldn't (my skill doesn't) come up with any errors.
just notice that  the code


condition ? X : Y


actually returns a value.


while the code


if (condition) {X) else {Y}


don't return any value.
Oh! I've actually made an attack kinda sorta like this!


b.isStateAffected(10)? (a.atk + a.mat) * 0.4 : b.addState(10)


While my skill is seeing if the target is affected by the state (in this case, my poison state), it deals a lot of damage (for my game.) If the target is not poisoned, it is now. :3


To change it to your skill, we would do this:


a.isStateAffected(13)? (a.remove_state(13) ; a.atk * 4 - b.def * 2) : a.addState(13)


This is asking "Is the user effected by State 13? If so, remove the state and deal (a.atk * 4 - b.def * 2) damage to the target. If not (Else), then apply State 13 to the user."


In honesty, you don't need to add the "; 0" to your else statement. If you don't have it, it can't do anything, and this way shouldn't (my skill doesn't) come up with any errors.



"a.isStateAffected(13)? (a.remove_state(13) ; a.atk * 4 - b.def * 2) : a.addState(13)" still doesn't do anything, I'm still getting zeros.
Maybe it's the semicolon? Have you tried removing that?


Try this: (I've learned a little bit more about JavaScript since my last post:


"a.isStateAffected(13)? (a.remove_state(13) && a.atk * 4 - b.def *2) : a.addState(13)"


If that is still not working, try "a.removeState" instead of "a.remove_state"
Maybe it's the semicolon? Have you tried removing that?


Try this: (I've learned a little bit more about JavaScript since my last post:


"a.isStateAffected(13)? (a.remove_state(13) && a.atk * 4 - b.def *2) : a.addState(13)"


If that is still not working, try "a.removeState" instead of "a.remove_state"

Well, adding "&&" and "removeState" did help since now the attack does add and remove the state, but the damage is still nothing in both cases.


The formula is now "a.isStateAffected(13)? (a.removeState(13) && (a.atk * 4 - b.def * 2)) : a.addState(13)"

Original thread: https://forums.rpgmakerweb.com/threads/is-my-formula-good.62149/