Formula question

I have a query about the damage formula in RPG maker mv.
Can two if/else statements be used within each other.
Code:
if (a.isActor()) 75 + (a.mat * (v[52] + v[54])) - b.mdf * 2; else 75 + (a.mat * 5) - [new if & else statement] b.mdf * 2;
for example an if statement placed here;
Why don't you put it in game & try it yourself?
I guess I could overpush the limits on how much damage to see if it works.
These two lines are equivalent when used in the damage formula box:
Code:
if (a > b) a - b; else a + b
a > b ? a - b : a + b
However, the second line is what to use whenever you want to "if" something mid-line, e.g.
Code:
if (a.isActor()) 75 + a.mat*(v[52] + v[54]) - b.mdf*2; else 75 + (a.mat*5) - (b.def < b.mdf ? b.def : b.mdf) * 2
Remember to put it in brackets so you're sure what's included in the statement and what isn't. ^_^

Another option, depending on what you're trying to do, is to follow your "else" clause with another "if", e.g.
Code:
if (a.isActor()) 10; else if (b.isActor()) 20; else 0
This will do 10 damage if the user is an actor, 20 if the target is an actor but the user isn't (because it's after the first "else"), and 0 otherwise.
Thanks that should help with what I want to do.
I wanted to increase def based on if the target is an actor or enemy.
This is the new formula should be able to check if it works later
Code:
if (a.isActor()) 75 + (a.mat * (v[52] + v[54])) - b.mdf * 2; else 75 + (a.mat * 5) - (b.def < b.mdf ? b.def * 2 : b.mdf * 3);
As-is, that's comparing the target's def and mdf stats against one another. If you want to check whether the target is an actor or enemy, you might want something like this instead:
Code:
...stuff goes here... - (b.isActor() ? b.mdf * 4 : b.mdf * 2)
I.e. "if the target is an actor, subtract 4 times their mdf stat, otherwise subtract 2 times their mdf".

Original thread: https://forums.rpgmakerweb.com/threads/formula-question.103683/