Karbonic

Off Brand OFF
Veteran
Joined
Dec 24, 2015
Messages
92
Reaction score
28
First Language
English
Primarily Uses
RMMV
Hi! I'm looking for a script command to toggle set switch on and off.
Doing so using the normal switch control command would require a conditional branch to check whether it is already on or off, which I'd like to avoid.

Basically, I'm looking for an MV equivalent of this VXA solution.

I hope to hear from you soon! Thanks a bunch!
 

JGreene

Veteran
Veteran
Joined
Oct 24, 2015
Messages
452
Reaction score
360
First Language
English
Primarily Uses
RMMV
Never tried a script call like that, but see if this works.

var x = 1 // Your switch #
var toggle = !$gameSwitches.value(x);
$gameSwitches.setValue(x, toggle);
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
680
Reaction score
321
First Language
PT-BR
Primarily Uses
RM2k3
Try:
JavaScript:
$gameSwitches.setValue(1, !$gameVariables.value(1));

Reference:

JavaScript:
var mybolean = false;
mybolean = !mybolean; //retun true
mybolean = !mybolean; //retun false
 
Last edited:

Karbonic

Off Brand OFF
Veteran
Joined
Dec 24, 2015
Messages
92
Reaction score
28
First Language
English
Primarily Uses
RMMV
var x = 1 // Your switch #
var toggle = !$gameSwitches.value(x);
$gameSwitches.setValue(x, toggle);
JavaScript:
$gameSwitches.setValue(1, !$gameVariables.value(1));
Both of these solutions work great! I decided to go ahead and combine them together to make the easiest plug and play command I could, here it is.

JavaScript:
var x = 1
$gameSwitches.setValue(x, !$gameSwitches.value(x));

This way, the switch number only needs to be put manually into the script once, so I'll be less likely to make a mistake.
Thanks a bunch, everyone!
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
680
Reaction score
321
First Language
PT-BR
Primarily Uses
RM2k3
In fact, the two answers are the same ...
I had not read the whole topic, as it was not connected to my computer.
To help, I'll leave a method for testing whether a variable is "true" or "false":
JavaScript:
Boolean(var)

Examples:
JavaScript:
Boolean(1); //true
Boolean(2); //true
Boolean(999); //true
Boolean(0); //false
Boolean("String"); //true
Boolean(""); //false
Boolean(null); //false
Boolean("null"); //true
Boolean(undefined); //false
 

Latest Threads

Latest Posts

Latest Profile Posts

Just a little close up shot...
w2xZocX.jpg
finally drew the last member of "team outcast" for my game. since my game has a lot fighting game elements in it, there's bosses in teams of three like King of Fighters.
Run Script Calls & Play Unique Sound Effects With Each Skill & Item | RPG Maker News #113

Let's continue making our game in MZ! Touchfuzzy is... still eventing... though this time we may be working on eventing some tutorial stuff for our players!

I work late on the game so I sleep in then I wake up late so I have to work hard to make up for sleeping in meaning I work late again and sleep in again... what a nasty cycle.

Forum statistics

Threads
113,844
Messages
1,077,912
Members
147,925
Latest member
DrimCr
Top