Turning off all self switches in a map?

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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.
 

Heartbreak61

Wandering Noob
Veteran
Joined
Sep 5, 2012
Messages
187
Reaction score
90
First Language
Indonesian
Primarily Uses
RMMV
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;}}
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
Thank you very much! Dirty works for me. ;)
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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); });
 
Last edited by a moderator:

Heartbreak61

Wandering Noob
Veteran
Joined
Sep 5, 2012
Messages
187
Reaction score
90
First Language
Indonesian
Primarily Uses
RMMV
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
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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);  		}  	}  }};
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top