MZ Checking if switch is on not working

Hello lovely people!

I'm using bottom script below to trigger a game message and turning on a switch if that switch is off.

However, I'm getting the game message when the switch is on as well, so I must be doing something wrong with the JS.

1610771496497.png
You have an OR and an AND in the same condition, so it will be evaluated from left to right - if variable 1 is 12, it won't check the other things.

If you want variable 1 to be 12 or 13 AND switch 23 is off, put parentheses around the two variable checks:

Code:
if (($gameVariables.value(1) == 12 || $gameVariables.value(1) == 13) && !$gameSwitches.value(23)) {
  do stuff
}

Though you could have done all of that using event commands anyway
You have an OR and an AND in the same condition, so it will be evaluated from left to right - if variable 1 is 12, it won't check the other things.

If you want variable 1 to be 12 or 13 AND switch 23 is off, put parentheses around the two variable checks:

Code:
if (($gameVariables.value(1) == 12 || $gameVariables.value(1) == 13) && !$gameSwitches.value(23)) {
  do stuff
}

Though you could have done all of that using event commands anyway
Oh yeah!
Thanks @Shaz!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/checking-if-switch-is-on-not-working.132274/