"Switch toggle" function

Hi,

I tried to create myself a "switch toggle" function, as I couldn't find something like that in the built-in commands, and it seems easy to implement.

I created a new function in the gameSwitches class, and it looks like this:

Code:
Game_Switches.prototype.toggle = function(switchId) {
    if (this.value(switchId)) {
        this.setValue(switchId, false);
    } else {
        this.setValue(switchId, true);
    }
};

however when I test it, it looks like the switch is turned ON, but reverts instantly to OFF, though the process is called once.


Is there something I did wrong ?

EDIT : I found the problem, it was my fault : I had a second page on the event ^^' sorry for posting
Don't worry about it. If we got a dollar for every time the solution became obvious as soon as someone posted a thread, then I think we could pay for a copy of MV for everyone. 🤣

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/switch-toggle-function.118878/