Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MrAbu on Sat 02/12/2017 22:42:49

Title: Doing things at given intervals in a timer
Post by: MrAbu on Sat 02/12/2017 22:42:49
So with some help I made a timer a little bit ago and it worked great, so now  im experimenting with it. I set the timer to 10 seconds and had it countdown. This works fine. My issue now comes from two parts. First, I wanted to add in something to happen when the timer was halfway done (timerValue == 5). This does what it's meant to, but then instead of continuing the countdown it's skipping straight to when the timerValue is 0 and repeating that. Secondly, I tried taking out the halfway event. The timer counts down to 0 but it won't reset like how I want it to. I put the whole thing in the Repeatedly Execute function for a room. Basically I'm asking how to reset the timer, and how to make something happen in the middle of the timer.

Code (ags) Select

if (timerActive)
{
   if (timerValue == 0)                   // when time expires
    {
      // timer expired
      timerActive = false;                // pause timer now by calling timerActive = false
      Display("Check");                   // so i know when the timer expires
      FadeOut(30);
      StartCutscene(eSkipESCOnly);
      CharacterReset();                  // reset the day
      timerValue = 10;
      timerActive = true;
      EndCutscene();
      FadeIn(30);
     
     
      if (iChar[17] == 1)
      {
        dGabiVaca.Start();
      }
    }
   else if (timerValue == 5)              // do something when timer hits a certain time, then keep counting
    {
      cAlyssa.ChangeRoom(1,  733, 216);   // change room at certian time   
      timerValue--;                       // continue counting down
       
    }
    else timerValue--;                    // countdown... might make it a count up
}
Title: Re: Doing things at given intervals in a timer
Post by: Mandle on Sat 02/12/2017 23:55:08
Is cAlyssa the player character?

If so then I believe this script will stop at the moment the player character moves to another room.
Title: Re: Doing things at given intervals in a timer
Post by: MrAbu on Sun 03/12/2017 00:13:21
No. cAlyssa is an NPC, should have made that clear, sorry
Title: Re: Doing things at given intervals in a timer
Post by: dayowlron on Sun 03/12/2017 03:24:40
I just have one comment to make. You are setting TimerValue to 10 but then if this code is in RepExec function then it is happening something like 30 times a second. When you reset the timer and check for the halfway point multiply the values times the game speed.
Title: Re: Doing things at given intervals in a timer
Post by: MrAbu on Sun 03/12/2017 03:40:25
That fixed it! I didn't notice that the 5 second interval wasn't actually 5 seconds, thanks dayowIron!