How to turn on switch if a variable is equal to many possible values

Sinvergil

Villager
Member
Joined
Apr 10, 2012
Messages
17
Reaction score
7
Primarily Uses
Hey there! I am trying to figure out how to turn on a switch if a variable is equal to a bunch of possible values? What I got so far is something like this...

So I have an event that sets variable 1 to the value of 115. And then I create the following script call:

var hs = [113, 114, 115, 116, 117];
if ($gameVariables.value(1) === hs) {
$gameSwitches.setValue(100, true);
}


So basically if variable #1 is equal to 113, 114, 115, 116, or 117, game switch 100 will turn on. I'm no programmer so I'm not entirely sure how to do this part exactly. I can do this through a bunch of conditional branches but what if variable 1 can be equal to lets say 1000 different numbers, then I'd have a bunch of conditionals :) . Any help would be greatly appreciated! Thank you!!!!
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
PHP:
const isIn= [113, 114, 115, 116, 117].includes($gameVariables.value(1) )||false;
$gameSwitches.setValue(100, isIn);
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Contains, not includes. Includes is present only from MV 1.6.0
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
I guess he uses 1.6, he does not say is the version!
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
480
Reaction score
1,468
First Language
Indonesia
Primarily Uses
RMMV
A neater, shorter version :
Code:
$gameSwitches.setValue(switchID, [value1, value2, value3, etc].contains($gameVariables.value(variableID)))
or you can do it like this in case you want to do more :
eventing.JPG
 

Sinvergil

Villager
Member
Joined
Apr 10, 2012
Messages
17
Reaction score
7
Primarily Uses
Wicked! Thank you so much guys! This helped me in so many ways :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top