Clear ALL selfswitches

Hello! 🙂

I'm doing a puzzle game and to be able to restart the level, I need to clear all the self switches of the map, BUT not all the selfswitches of the game (cause I have a common area which has self switches).

I know that this script code: $gameSelfSwitches.clear() clears all the self switches, but I need something similar only for the map ID I want.

Is it possible to do that?

Thanks! 🙂
My first question is:  Where are you using that script code at in your game?

My second question is:  Wouldn't it be easier, on an event that exits the map, to simply reset the self-switches for that map after a Fadeout Screen and before a Transfer Player event?

So it would be like --  Fadeout Screen

                                  Control Self Switch A = OFF

                                  Control Self Switch B = OFF

                                  Control Self Switch C = OFF

                                  Control Self Switch D = OFF

                                  Transfer Player = Map, (x, y)

                                  Fadein Screen
So it would be like --  Fadeout Screen

                                  Control Self Switch A = OFF

                                  Control Self Switch B = OFF

                                  Control Self Switch C = OFF

                                  Control Self Switch D = OFF

                                  Transfer Player = Map, (x, y)

                                  Fadein Screen
That seems easier, specially if those commands start by a big Switch from another event.

You know, the event that exits the map would do this

Fadout Screen

Switch ON

Transfer Player = Map (X,Y)

Fadein Screen. 

The switch will trigger the last page ( paralel process) of all of your events  with self switches, and that page will do the 

                                  Control Self Switch A = OFF

                                  Control Self Switch B = OFF

                                  Control Self Switch C = OFF

                                  Control Self Switch D = OFF

                         Control Switch = OFF

 

I'm almost sure that none of the events will stay with the selfswitches with this, and also you could use the switch for future maps.
That seems easier, specially if those commands start by a big Switch from another event.

You know, the event that exits the map would do this

Fadout Screen

Switch ON

Transfer Player = Map (X,Y)

Fadein Screen. 

The switch will trigger the last page ( paralel process) of all of your events  with self switches, and that page will do the 

                                  Control Self Switch A = OFF

                                  Control Self Switch B = OFF

                                  Control Self Switch C = OFF

                                  Control Self Switch D = OFF

                         Control Switch = OFF

 

I'm almost sure that none of the events will stay with the selfswitches with this, and also you could use the switch for future maps.
Uh, wouldn't that turn off the Self-Switches for the map moved into?  I guess I'm just a little afraid of the way that looks.  I ought to try it myself and see if it works that way.
Do you only want to do this for a single map? In that case, make a Script command like this:

keys = Object.keys($gameSelfSwitches)keys.forEach(function(ssid)) { map = ssid[0] if (map == X) { $gameSelfSwitches[ssid] = false }}Replace the X in the (map == X) line with the map id, no leading zeros. So if you wanted to do it on map 15, that line would read:
Code:
if (map == 15)
If you want to do it on several maps, you could put the above into a common event and change that line to this:

if (map == $gameVariables.value(X))where X this time is the id of a variable.Then you could use Control Variables to set it to whatever map you wanted to reset self switches on, and Call Common Event to execute the above.
Thank you Shaz! 🤣

Original thread: https://forums.rpgmakerweb.com/threads/clear-all-selfswitches.53436/