Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: reismahnic on Sun 13/03/2016 22:51:11

Title: Wait command is interrupting timer!
Post by: reismahnic on Sun 13/03/2016 22:51:11
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).


Code (ags) Select

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.
Title: Re: Wait command is interrupting timer!
Post by: Scavenger on Sun 13/03/2016 23:09:42
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:

Code (AGS) Select

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);
        }
    }
     
Title: Re: Wait command is interrupting timer!
Post by: reismahnic on Sun 13/03/2016 23:21:18
Works perfectly. Thanks so much.
Title: Re: Wait command is interrupting timer!
Post by: Khris on Mon 14/03/2016 14:14:32
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?
Title: Re: Wait command is interrupting timer!
Post by: reismahnic on Wed 16/03/2016 07:51:48
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.