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 Profile Posts

*sigh* This one turned out really well... except for the left arm pose...
fPRzKSp.jpg

Yes I purposely cutout the arm cause from the pic
A month into making my life/dating sim game and I've finally finished making all of the love interests :kaocry: I still have to make most of their emotion range and overworld sprites but aye I'm proud of myself.
would i get in trouble if i didn't take out the computer icons on my fake computer screen i had Discord, Messanger, and rpg maker up
Auto-Adjust Text Outline, Run Common Events on Transfer | RPG Maker News #111

I sweep the floor. My brother, "You didn't do a good job. There are dust bunnies everywhere." He sweeps the floor weeks later. "I just swept. Why are there dust bunnies everywhere?" Me," Guess you didn't do a good enough job."

Forum statistics

Threads
113,791
Messages
1,077,512
Members
147,837
Latest member
Fenrir_
Top