Author Topic: Doing things at given intervals in a timer  (Read 235 times)

Doing things at given intervals in a timer
« on: 02 Dec 2017, 22:42 »
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: Adventure Game Studio
  1. if (timerActive)
  2.  {
  3.    if (timerValue == 0)                   // when time expires
  4.     {
  5.       // timer expired
  6.       timerActive = false;                // pause timer now by calling timerActive = false
  7.       Display("Check");                   // so i know when the timer expires
  8.       FadeOut(30);
  9.       StartCutscene(eSkipESCOnly);
  10.       CharacterReset();                  // reset the day
  11.       timerValue = 10;
  12.       timerActive = true;
  13.       EndCutscene();
  14.       FadeIn(30);
  17.       if (iChar[17] == 1)
  18.       {
  19.         dGabiVaca.Start();
  20.       }
  21.     }
  22.    else if (timerValue == 5)              // do something when timer hits a certain time, then keep counting
  23.     {
  24.       cAlyssa.ChangeRoom(1,  733, 216);   // change room at certian time    
  25.       timerValue--;                       // continue counting down
  27.     }
  28.     else timerValue--;                    // countdown... might make it a count up
  29.  }


    • Mandle worked on a game that was nominated for an AGS Award!
Re: Doing things at given intervals in a timer
« Reply #1 on: 02 Dec 2017, 23:55 »
Is cAlyssa the player character?

If so then I believe this script will stop at the moment the player character moves to another room.

Re: Doing things at given intervals in a timer
« Reply #2 on: 03 Dec 2017, 00:13 »
No. cAlyssa is an NPC, should have made that clear, sorry


  • been programming computers since 1981
    • I can help with AGS tutoring
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
Re: Doing things at given intervals in a timer
« Reply #3 on: 03 Dec 2017, 03:24 »
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.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Re: Doing things at given intervals in a timer
« Reply #4 on: 03 Dec 2017, 03:40 »
That fixed it! I didn't notice that the 5 second interval wasn't actually 5 seconds, thanks dayowIron!