Troubles with a damage formula

The formula is: "if b.isStateAffected(0051) {((a.atk * 8) - (b.def * 2)) * 2} else {(a.atk * 8) - (b.def * 2)}"

Always does 0 damage (doesn't matter if b is affected or not).
b.isStateAffected(51) ? (a.atk * 8 - b.def * 2) * 2 : a.atk * 8 - b.def * 2;

the leading 0s for the state id shouldnt be there.

to many brackets (shouldnt actually break it but they are unnecessary because of how B/E/DM/AS works)
b.isStateAffected(51) ? (a.atk * 8 - b.def * 2) * 2 : a.atk * 8 - b.def * 2;

the leading 0s for the state id shouldnt be there.

to many brackets (shouldnt actually break it but they are unnecessary because of how B/E/DM/AS works)
It works now, thank you
Just a quick additional note - while the ternary operator form that Tiamat-86 is definitely more efficient in this instance, if you do need to use if statements someplace else, JavaScript requires the condition to be in parentheses: if (condition)

That's another reason your original code wouldn't have worked.
just to add an explanation why leading zeroes are bad.

in program code, the leading zeroes tell the computer what number format is about to be used.
You might have seen a notation like 0xFF for hexadecimal numbers for example.

00 is the code for octal numbers, so 0051 tells the computer to read 51 as an octal number, not as a decimal number. And octal 0051 is decimal 41 (5*8+1), so your condition is actually looking for the state with the ID=41.

And then fails because you forgot the correct parantesis...

I've gone ahead and deleted all the spam/troll posts made in this thread, as well as the responses to them.


@WingedHero If your issue is solved, please report this post and we'll close the thread. 🙂

Edit:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/troubles-with-a-damage-formula.145478/