Turning off all self switches in a map?

How would one do this in an efficient way?

I've got this, but

var key = [map id, event id, selfswitch];

$gameSelfSwitches.setValue(key, true);

Not sure how to apply ^ that on every event/self switch in map X.
Quick & dirty way
 
for (var i=0; i < Object.keys($gameSelfSwitches._data); i++) {if (Object.keys($gameSelfSwitches._data).match(/(\d+),/)[1] === YOUR_MAP_ID_HERE) {Object.keys($gameSelfSwitches._data) = false;}}
Thank you very much! Dirty works for me. 😉
Wouldn't that also reset all self switches belonging to events with the same id as that map, no matter on which map they are?


Also, i'm not sure why you're calling Object.keys() 3 times, when 1 would be enough and your last call is even wrong, because you are not resetting the switch value, but change the key it belongs to.
Wouldn't that also reset all self switches belonging to events with the same id as that map, no matter on which map they are?

Also, i'm not sure why you're calling Object.keys() 3 times, when 1 would be enough and your last call is even wrong, because you are not resetting the switch value, but change the key it belongs to.
Does it? O___o

Then what would the better way be?

Edit: Oh yeah, it's not actually working... I just tested it out using this code:

var key = [this._mapId, 10, 'A'];alert($gameSelfSwitches.value(key));Event 10's self switch A stays true after running the code posted above on that map id.
Game_SelfSwitches is kinda messy in that it uses Arrays as keys. JavaScript can only use Strings, so those arrays are converted to their string representation. The easiest way would be to just loop over all events in that map:

$gameMap.events().forEach(function(event) { ['A', 'B', 'C', 'D'].forEach(function(key) { $gameSelfSwitches.setValue([$gameMap.mapId(), event.eventId(), key]); });});This obviously only works for the current map, though.The shorter version would be this, but it relies on the string representation of the Array class, which might not be consistent across all browsers:

Code:
Object.keys($gameSelfSwitches._data).filter(function(key) { return /^(\d+)/.exec(key)[1] == MAP_ID; }).forEach(function(key) { $gameSelfSwitches.setValue(key); });
Thanks lavra for reminding me.

Stupidly, I tried to set switches keys rather than it's value to false. Moreover, after I take a look again, I see that setting self switches to false must be followed by refreshig the map

You might try to use lavra's snippet or use this. Call $gameSelfSwitches.clearMap(MAP_ID)

Game_SelfSwitches.prototype.clearMap = function(mapId) { var ary = Object.keys(this._data); for (var i = 0; i < ary.length; i++) { if (ary.match(/(\d+),/)[1] == mapId) { this.setValue([ary], false); } }}Pardon for my mistake XD
Yay, that works! Thank you!

I ended up doing it like this:

Code:
var mapIdsArray = [6,7,8,9,10,11,14,19,20,24,25,26,27,28,29,30,31,33,53];SceneManager.turnoffSelfSwitches(mapIdsArray);
Code:
SceneManager.turnoffSelfSwitches = function(mapIdsArray) {  for (var ii=0; ii < mapIdsArray.length; ii++) {    var mapIdTemp = mapIdsArray[ii];    var ary = Object.keys($gameSelfSwitches._data);  	for (var i = 0; i < ary.length; i++) {  		if (ary[i].match(/(\d+),/)[1] == mapIdTemp) {  			$gameSelfSwitches.setValue([ary[i]], false);  		}  	}  }};

Original thread: https://forums.rpgmakerweb.com/threads/turning-off-all-self-switches-in-a-map.50582/