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,863
Reaction score
14,514
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,863
Reaction score
14,514
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 Posts

Latest Profile Posts

I am adamant about not having missable quests, which means having to write entirely new scenes at each plot progression that takes into account that time and events have passed since the quest could first be accepted while still having there be a quest to solve in the first place. It's worth every second.
Surprisingly useful and thought provoking
Working on animation. Trying to see if I can apply it meaningfully to my games!
ddwk.png

working on the sprite for Devali <3
My Game Development Livestream

Forum statistics

Threads
110,378
Messages
1,052,790
Members
143,419
Latest member
haniffauziyatun
Top