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


I fixed the lips and noses for MZ! The files have been updated.
qQwgk8C.png

Everything below!
Ugh, I opened MV after a few weeks and I'm completely lost on what I was working on.
Does it happen to someone else or am I the only disorganized one around? :kaoswt:
xH5Fk2f.jpg
Today was not a really productive day, but at least i got some bust sketches going <3
E7QXZHNXoAIkpG8
hmm in exploring MZ with FOSSIL... I see I'll probably need to stick with MV for now as none of the menu altering plugins I use work on MZ lol. and I don't have the money to dump into what I would need in some cases to update plugins to their MZ versions. Everytime I think of converting, 5 or more reasons popup on why I shouldn't.
Hmm... Game has 91 views, 25 downloads, 5 reviews and netted me 7 additional followers. Meanwhile the image I posted just yesterday on Imgur to showcase it has 45,197 views. Interesting, I think I have a new advertising idea. Also Twitter? The post got 16 retweets, 20 likes, and 1,683 views.... And a whole 3 hits to my game, completely valueless. I am glad I did this game jam, this information is quite valuable.

Forum statistics

Threads
113,661
Messages
1,076,505
Members
147,681
Latest member
antales
Top