Hi, I am making a game in which the wait command will be active for minutes at a time.
However, I want certain timers to be able to go off DURING the wait command.
Obviously I understand that Wait puts everything on hold, so what I wanted to do was slot the effects of the timer between TWO wait commands if that's possible.
Here's what I tried (I'm typing this on my phone as I'm not in a place with internet, apologies).
function room_AfterFadeIn()
{
SetBackgroundFrame(0);
player.Say("Hello. This is gonna time out.");
SetTimer(1, 600);
Wait(601);
Player.Say("Huh?");
Wait(600);
}
function room_RepExec()
{
if (IsTimerExpired(1)==1)
{
SetBackgroundFrame(1);
}
}
Basically, what I WANT is for the character to speak, then the first wait happens, then the character speaks again and the background CHANGES, then another wait.
What I'm getting instead is that, but the background doesnt change until after the very end of the script, the final wait.
Thank you so much.
Room_RepExec doesn't run during blocking scripts, so it'll wait for the end of those waits to run. The timer, however, does seem to count down even during wait commands. You'll want to put your repExec code in repeatedly_execute_always instead, which runs even during blocking scripts:
function room_AfterFadeIn()
{
SetBackgroundFrame(0);
player.Say("Hello. This is gonna time out.");
SetTimer(1, 600);
Wait(601);
Player.Say("Huh?");
Wait(600);
}
function room_RepExec()
{
}
function repeatedly_execute_always ()
{
if (IsTimerExpired(1)==1)
{
SetBackgroundFrame(1);
}
}
Works perfectly. Thanks so much.
Wait, maybe I'm missing something, but why not simply do this?
player.Say("Hello. This is gonna time out.");
Wait(600);
SetbackgroundFrame(1);
Wait(1); // redraw screen
Player.Say("Huh?");
Wait(600);
Why use a timer in the first place if you are implementing a simple blocking sequence?
In the context of my specific project, I will need timers that are expiring upwards to 40 minutes after activation.
This was an example in the context of a short amount of time.
But you're right, IF that was all I wanted to do, a blocking sequence would be preferred.