That's also assuming you are only using map id and event id - the plugin allows you to call it just about anything, so if you happen to be using something that is NOT a map id, but it LOOKS like it could be a map id and in the same format, it will be deleted as well.
Multi Timers
JS Plugin Releases (RMMV)I think I found another way to make this work.
In my code I have self switch B turning on when the timer runs out. So what I was able to do was add this line of code on self switch B:
Now obviously this would never run until the timer ran out since self switch B will never turn on until the timer runs out.
However, what I did was force self switch B to turn on when I left the map. Of course it's sort of a brute force method since I'm turning on ALL self switch B's on the map, but it does work. I made one slight revision by changing the switch from self switch B to self switch D since I wasn't using it for any events.
The trick was actually using the documentation on @Galv event spawner plugin.
Normally when I want to reset all self switches on a map, I'd use this code (in this example just for self switch D):
But what's weird is that this doesn't work on spawned events. I tried over and over and it just wouldn't target the spawned events.
However, by changing "$dataMap.events.length;" to "$gameMap._lastSpawnEventId;" I was able to target all the spawned events on the map and turn on all of their self switch D. So the code now looks like:
Now when I leave the map I just run the above code which turns on self switch D on all the events (spawned and otherwise) which then deletes that event's timer, and then I next run GALV's plugin command "Galv.SPAWN.clear(4,true);" to clear all events on the map.
I did need to add one extra script before running my modified self switch script, and that was to reset GALV's eventID with:
For some reason not resetting this was causing performance issues and not fully resetting all the events on the map even after running the plugin command "Galv.SPAWN.clear(4,true);".
However, I've now been running my game all morning (for a few hours now) just spawning events, then leaving the map, then coming back and everything resets perfect. I've spawned over 2000 events as of right now without resetting and there's no performance issues and the timers all reset when I leave the map.
And when I say I've spawned over 2000 events, I never have more than 11 events on the map at any one time since the events erase themselves after about 30 seconds - I don't actually have 2000 events on my screen at once. I'm only testing to see how long the game will spawn 11 events all on their own individual timers then despawn before spawning a new event or when leaving the map and then coming back.
So basically I didn't really need to do anything weird with @Shaz code - I just used his standard documentation which says to use "deleteTimer", I just had to find a creative way (by reading everyone's documentation) to actually get that code to run on a spawned event.
Thanks for the help, everyone! If I do run into any issues, at least we still have this thread to refer to if we ever want to delete all timers with the code @Arthran wrote. And like @ATT_Turan implied - actually reading the documentation is usually the way to go lol.
In my code I have self switch B turning on when the timer runs out. So what I was able to do was add this line of code on self switch B:
Code:
deleteTimer <thismap>.<thisevent>
Now obviously this would never run until the timer ran out since self switch B will never turn on until the timer runs out.
However, what I did was force self switch B to turn on when I left the map. Of course it's sort of a brute force method since I'm turning on ALL self switch B's on the map, but it does work. I made one slight revision by changing the switch from self switch B to self switch D since I wasn't using it for any events.
The trick was actually using the documentation on @Galv event spawner plugin.
Normally when I want to reset all self switches on a map, I'd use this code (in this example just for self switch D):
Code:
var m = $gameMap.mapId();
for (var s = 1; s < $dataMap.events.length; s++){
$gameSelfSwitches.setValue([m, s, 'D'], true);}
But what's weird is that this doesn't work on spawned events. I tried over and over and it just wouldn't target the spawned events.
However, by changing "$dataMap.events.length;" to "$gameMap._lastSpawnEventId;" I was able to target all the spawned events on the map and turn on all of their self switch D. So the code now looks like:
Code:
var m = $gameMap.mapId();
for (var s = 1; s < $gameMap._lastSpawnEventId; s++){
$gameSelfSwitches.setValue([m, s, 'D'], true);}
Now when I leave the map I just run the above code which turns on self switch D on all the events (spawned and otherwise) which then deletes that event's timer, and then I next run GALV's plugin command "Galv.SPAWN.clear(4,true);" to clear all events on the map.
I did need to add one extra script before running my modified self switch script, and that was to reset GALV's eventID with:
Code:
$gameMap._lastSpawnEventId = 0;
For some reason not resetting this was causing performance issues and not fully resetting all the events on the map even after running the plugin command "Galv.SPAWN.clear(4,true);".
However, I've now been running my game all morning (for a few hours now) just spawning events, then leaving the map, then coming back and everything resets perfect. I've spawned over 2000 events as of right now without resetting and there's no performance issues and the timers all reset when I leave the map.
And when I say I've spawned over 2000 events, I never have more than 11 events on the map at any one time since the events erase themselves after about 30 seconds - I don't actually have 2000 events on my screen at once. I'm only testing to see how long the game will spawn 11 events all on their own individual timers then despawn before spawning a new event or when leaving the map and then coming back.
So basically I didn't really need to do anything weird with @Shaz code - I just used his standard documentation which says to use "deleteTimer", I just had to find a creative way (by reading everyone's documentation) to actually get that code to run on a spawned event.
Thanks for the help, everyone! If I do run into any issues, at least we still have this thread to refer to if we ever want to delete all timers with the code @Arthran wrote. And like @ATT_Turan implied - actually reading the documentation is usually the way to go lol.
I haven't looked at Galv's plugin, but you probably want to change it to
s <= Otherwise, it won't be toggling the self switch of the last/highest ID event on your map.
That's different because the first time you're referencing the length of the array, which has an entry for 0 that's unused by events. So if you have 6 events on your map, the highest ID is 6 but the length will be 7, and that works.
But if you're using the last spawned event ID and still using "less than," then the last spawned event might have an ID of 62 but you're stopping at 61.
Nice catch, thank you! I was wondering why there was always 1 event acting weird.
I just came to thank you for this work. You solved a problem I didn't know how to solve. Which was to disappear a window created with "ExtraWindow.js" by turning off the switch that invoded it.
PS: I am using them in MZ
PS: I am using them in MZ
Just wanted to say thanks for making this plugin, it's exactly what I needed!!
Hi @Shaz,
I am trying to do a basic timer to turn a switch off. This was one of the first questions you answered, but when I copied the code that you gave in that example it didn't work. I tested the event with a different creator's plugin and that worked so I'm wondering if I didn't download your plugin correctly. Here's what it looks like.
Thank you.
I am trying to do a basic timer to turn a switch off. This was one of the first questions you answered, but when I copied the code that you gave in that example it didn't work. I tested the event with a different creator's plugin and that worked so I'm wondering if I didn't download your plugin correctly. Here's what it looks like.
Thank you.
Nevermind. I figured it out. The problem is I'm a newb.
Original thread: https://forums.rpgmakerweb.com/threads/multi-timers.50474/