[SOLVED] Resetting all self switches to OFF state upon game start... Need optimizing, please.

Hi, I am having a blast using MV. My game demo allows for saving at the end for a sort-of NewGame+ mode, where you keep all your experience, items and gold. But I noticed that all self switches I used were still set ON. I guess that is to be expected, though.

Because those self switches hinder the second cycle of the game, I needed to find out a way to turn them all OFF. After looking through the forums last night, I decided to brute force it at the introduction, but I still think I need to heavily optimize my code.

I am using the following Script call at my introduction scene:

Code:
for (var mapId = 1; mapId < 999; mapId++) {  for (var eventId = 1; eventId < 999; eventId++) {    $gameSelfSwitches.setValue([mapId, eventId, 'A'], false);    $gameSelfSwitches.setValue([mapId, eventId, 'B'], false);    $gameSelfSwitches.setValue([mapId, eventId, 'C'], false);    $gameSelfSwitches.setValue([mapId, eventId, 'D'], false);  }} 
But it takes about... ten to fifteen seconds to run through that loop. Also, I fear it takes even longer as I add more maps and events on the game. Thus, I'd like to know a few things. Instead of running through 999 maps (or whatever I set the number as), is there a way to run only as many loops as there are maps? I tried something like mapId.length but ran into errors. Also, the second loop. I know there is this $dataMap.events.length, but isn't that referring to the current loaded map? I might have pulled that from the 'Outer Self Switch' plugin or from the forums, can't really remember at the moment.

 

Thanks in advance.

-Zelgadis85
Also, I fear it takes even longer as I add more maps and events on the game.
Probably not since your current code already runs through all possible instances of self switches since you're already looping thru all possible maps and all events in those maps (I mean you're even doing this for maps and events that are not existent)


You could probably try to run them in separate batches during maybe the end credits before the NG+ save file is made or something...
You're overthinking it 🙂

Code:
$gameSelfSwitches.clear()
will remove all of them in one hit.
D'oh. I thought that there might be a simpler answer, but I wasn't expecting a clear command. 🙂  

Thanks, Shaz. That really helped me.

This topic may be closed now.

Original thread: https://forums.rpgmakerweb.com/threads/solved-resetting-all-self-switches-to-off-state-upon-game-start-need-optimizing-please.49699/