Switch Toggling?

Is there a way to toggle Switches from ON to OFF and vice versa without having to check if the switch either on or off first constantly?

I remember one of the earlier RM's had this feature [I think it was XP], where it automatically toggles a switch to the on/off position based on its current position. IE: if the switch was 'on' then the command would turn it 'off' automatically.

Is there a way to do that in MV?
I don't know if there's a built-in function but you could write one
if($gameSwitches.value(x)){
$gameSwitches.setValue(x,false);}
else{
$gameSwitches.setValue(x,true);}
$gameSwitches.value(x) = !$gameSwitches.value(x)
$gameSwitches.value(x) = !$gameSwitches.value(x)
Does that actually work? I thought you had to use setValue
Does that actually work? I thought you had to use setValue
maybe or $gameSwitches.setValue(x) = !$gameSwitches.value(x)

either 1 should work 🙂 but this is a scriptcall.

yours work too, but it depends, as I have a function with a scriptcall

ToggleSwitch(x) and it swich ON or OFF on the fly xD

Edit:

Scriptcall for toggle:
JavaScript:
$gameSwitches.setValue(x, !$gameSwitches.value(x));

as for my base function:
JavaScript:
    function toggleSwitch(id) {
        return $gameSwitches.setValue(id, !$gameSwitches.value(id));
    };
I don't know if there's a built-in function but you could write one
if($gameSwitches.value(x)){
$gameSwitches.setValue(x,false);}
else{
$gameSwitches.setValue(x,true);}
Thanks for this, but isn't this just a scripted version of the conditional branch in the events?

maybe or $gameSwitches.setValue(x) = !$gameSwitches.value(x)

either 1 should work 🙂 but this is a scriptcall.

yours work too, but it depends, as I have a function with a scriptcall

ToggleSwitch(x) and it swich ON or OFF on the fly xD

Edit:

Scriptcall for toggle:
JavaScript:
$gameSwitches.setValue(x, !$gameSwitches.value(x));

as for my base function:
JavaScript:
    function toggleSwitch(id) {
        return $gameSwitches.setValue(id, !$gameSwitches.value(id));
    };
How would this be used? The function I mean... Do I need to make a new plugin and install it then I can use the function...

--------------------------------------------

From what I can tell it's not going to be as easy as it was in XP to toggle the switches for a switch puzzle...
How would this be used? The function I mean... Do I need to make a new plugin and install it then I can use the function...
Yes, ShadowDragon's script works if you paste it in a plugin file then call it from an event page
Yes, ShadowDragon's script works if you paste it in a plugin file then call it from an event page
Thank you

Original thread: https://forums.rpgmakerweb.com/threads/switch-toggling.170906/