Status
Not open for further replies.

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
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
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,861
Reaction score
14,512
First Language
English
Primarily Uses
RMMV
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
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
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!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,861
Reaction score
14,512
First Language
English
Primarily Uses
RMMV

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.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

My Game Development Livestream

Of course, so, someone had covid at work today and I was exposed to them, so, I'm stuck at home for...TWO WEEKS!
oh god I'm going to die
AAAAAAAAi.png
Kind of relieved that I had medibang installed when I need to edit Sprite I was about to download gimp but I remember I had medibang installed lol

Forum statistics

Threads
110,368
Messages
1,052,666
Members
143,402
Latest member
IBanana
Top