How to pause a timer?

Started by MrAbu, Sun 26/11/2017 05:44:36

Previous topic - Next topic

MrAbu

I understand how to create and start a timer, and I know how to stop a timer, but is there a way to pause the timer and resume it from the paused point later?


Khris

AGS doesn't support pausing timers, but you can always use your own variable instead.

Code: ags
// top of script
bool timerActive;
int timerValue;


Code: ags
  // start timer
  timerActive = true;
  timerValue = GetGameSpeed() * 30; // 30 seconds


Code: ags
  // in repeatedly_execute / room_RepExec
  if (timerActive) {
    if (timerValue == 0) {
      // timer expired
      timerActive = false; // turn off
      // STUFF HAPPENS
    }
    else timerValue--;  // count down
  }


You can now pause the timer at any point by calling timerActive = false;

Monsieur OUXX

 

SMF spam blocked by CleanTalk