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
320
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
320
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

Feeling cute, might make an essay on the presence of Malaise in the gaming industry. idk
Just went to Metrocon here in Tampa Florida. My first anime convention. They had an anime chess battle and some funny impromtu comedy. The comedy was my favorite part. How is everyone?
I'm thinking about opening a "game in development" thread, though i'm not entirely sure yet. It's still really early in development, and most i have to show are assets or really chaotic map WIPs. There is a lot of story +the world itself though, and i struggle with converting all of my notes into readable text, and a thread might help...?
I see a button in a game, I press it. Cannot resist the temptation even if I know it's a trap.

Forum statistics

Threads
113,594
Messages
1,076,081
Members
147,590
Latest member
LiYe
Top