I am setting up a system where if you sign up for some newsletter, you get a spam email every now and then. But, this timing looks a bit cluttered as a common event. Is there a better way to set up a wait command instead of using frames? Seconds/minutes instead perhaps?
Better time wait method?
RPG Maker MZ SupportYou can try a method that uses the real-time clock rather than the game's frame counter
Then for your if conditional, the script to check if the current time is at or past your stored time looks like this:
Be sure to replace varId with whatever variable index you assign your stored time value.
Code:
//Return the current time in milliseconds since Jan 1, 1970
var now = Date.now();
// Set the next time for this spam message to appear 30 minutes from now.
//30 minutes * 60 seconds/min * 1000ms / second = 1,800,000 milliseconds
var nextSpamTime = now + 30 * (60 * 1000);
$gameVariables.setValue(varId, nextSpamTime);
Then for your if conditional, the script to check if the current time is at or past your stored time looks like this:
Code:
Date.now() >= $gameVariables.value(varId);
Be sure to replace varId with whatever variable index you assign your stored time value.
Thanks for the help. Unfortunately, I understand almost nothing about where to begin with scripting, and where I would put each of these code bits. Do I place the first one where the "wait 999 frames" is supposed to go, and where do I place the second block of code?
Script calls when pasted into an event are executed when the event runs. You can try this:
And I also recommend that you call the first block of code the moment your player signs up for a newsletter. Otherwise you'd get a spam message immediately after signing.
This way, right?
I believe I set this up already separately from the timer, thanks!
You'd need to replace
I would also suggest adding a Wait 60 frames command at the end of the event, because it doesn't need to check every frame.
varId in the condition with the appropriate number, e.g. 1 if you've stored the timestamp in variable ID 1.I would also suggest adding a Wait 60 frames command at the end of the event, because it doesn't need to check every frame.
Parallel events reset every time you change map, so the event in your first screenshot would only proc if you stayed on the same map for...uh...18x999 frames, which is a long time. 😅
A better approach is to have the Parallel event do something every few frames, e.g.
Or you can do as Gensun suggested~
A better approach is to have the Parallel event do something every few frames, e.g.
◆If:Spam Timer = 0
◆Comment:Spam time!
◆Common Event:Spam Email
◆Comment:Reset variable.
◆Control Variables:#0001 Spam Timer = 3000
◆
:Else
◆Comment:Tick down timer by 1.
◆Control Variables:#0001 Spam Timer -= 1
◆
:End
◆Comment:Check again in 6 frames.
◆Wait:6 framesOr you can do as Gensun suggested~
As long as we're mindful that your suggested approach also has a side effect of triggering every event on the current map to update its pages every time a variable is changed. This has potential to cause lag on large maps. We could also make it trigger once every-so seconds as an alternative
I did do this
oh... (That amount of time was honestly just an example, but yes, I don't plan on staying on a map that long lol!)
I'll see how I can approach this. Thanks!
As caethyril mentioned, if you do it Gensun's way, you definitely want to add a wait to the end of the event, because it's overkill to check the clock 60 times every second for something like this.
Depending on how you want the timer to work, you also might consider using
Depending on how you want the timer to work, you also might consider using
$gameSystem.playtime() instead of Date.now(). The difference is that $gameSystem.playtime() will pause when the player exits the game, whereas Date.now() will count time spent while the game was closed (i.e. they will get a spam mail as soon as they load the game if they've been gone for too long). So if you want the timer to stop when the player exits the game, it'd be something like this instead:On the other hand we'd definitely go overkill on annoyance if the spam system worked real-time and it spams the player instantly on the next day 

Original thread: https://forums.rpgmakerweb.com/threads/better-time-wait-method.164590/