Karbonic

Off Brand OFF
Veteran
Joined
Dec 24, 2015
Messages
90
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
579
Reaction score
249
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
90
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
579
Reaction score
249
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

I've been in Fort Myers since Thursday night. I'm going home tomorrow or the next day... lol, I desperately need a good taste of homemade Japanese food. I might not be Japanese or even Asian (I'm American born and raised), but I absolutely love authentic Japanese cooking. Restaurant food doesn't do it justice.
Haven't been working on any of my projects or resources lately as I'll soon be moving to a new apartment. It's been a stressful move but I'm really looking forward to it.
//Sees it's the same price at Best Buy for a new SSD as Amazon
//Sees it's 103F outside and Best Buy is half a hour of driving.
//Orders from Amazon.
I'll wait the 2-3 days. :LZSwink:
Just a little teaser screenshot of Mountain Village...

Screenshot (364).png

Forum statistics

Threads
112,373
Messages
1,067,867
Members
146,025
Latest member
urmomsbigbazoongas
Top