A redesign of the AGS site is now ready to be implemented! Please help us with art and content.

Author Topic: How do I represent a timer (in game ticks) as H:M:S?  (Read 107 times)

bx83

  • benjamin.rich@protonmail.com
Is there a wonderful way of saying:

Code: [Select]
#define TIMER_BOMB 1
SetTimer(TIMER_BOMB,GetGameSpeed()*10*60);   //10 minutes
Display("You have %d:%d till bomb explodes",<get how much time in seconds is left from timer 1>);

This is all something I've pulled out of my arse, but you get what I mean. How do we get the current time-out for a timer? Or should I use the module timer, which will take me.... a long time.

Matti

Re: How do I represent a timer (in game ticks) as H:M:S?
« Reply #1 on: 22 Jul 2021, 11:12 »
You could have two variables, seconds an minutes. If seconds reach -1, set them to 59 and decrease the minutes by 1.

Alternatively you could make a while loop that substracts 60 from a number of seconds until there are less than 60 seconds left, while adding +1 to a minute variable. The first solution should be simpler though.

Re: How do I represent a timer (in game ticks) as H:M:S?
« Reply #2 on: 22 Jul 2021, 11:51 »
Here's how I'd do this:

Code: Adventure Game Studio
  1. int frames;
  2.  
  3. function room_Load() {
  4.   frames = GetGameSpeed() * 60 * 10; // 10 minutes
  5. }
  6.  
  7. function Splode() {
  8.   Display("BOOM");
  9. }
  10.  
  11. function room_RepExec() {
  12.   if (frames == 0) Splode(); // timer runs out -> bomb explodes
  13.   if (frames > -1) {  // if timer is not negative, update display
  14.     int seconds = frames / GetGameSpeed();
  15.     int minutes = seconds / 60;
  16.     int timerSeconds = seconds % 60;
  17.     lblTimer.Text = String.Format("You have %02d:%02d till bomb explodes", minutes, timerSeconds);
  18.     frames--;  // count down until -1
  19.   }
  20. }

bx83

  • benjamin.rich@protonmail.com
Re: How do I represent a timer (in game ticks) as H:M:S?
« Reply #3 on: 23 Jul 2021, 02:21 »
Khris, fantastic it works :)

Code: [Select]
function repeatedly_execute_always()
{
...

    //do sacebar coordinates
    if (ovCoordsVisible) {
      //BookTranslationTimer - number of game loops it takes to translate homer's book
      //PuppetTimer - number of game loops it takes to make current puppet
     
      //timer countdowns
      if (BookTranslationTimer>=0) BookTranslationTimer-=1;
      if (PuppetTimer>=0) PuppetTimer-=1;
     
      int GameSpeed=GetGameSpeed();
     
      int BSec=BookTranslationTimer/GameSpeed;
      int BMin=BSec/60;
      int BTimerSec=BSec%60;
     
      int PSec=PuppetTimer/GameSpeed;
      int PMin=PSec/60;
      int PTimerSec=PSec%60;
     
      if (ovCoords != null && ovCoords.Valid) ovCoords.Remove();
      ovCoords = Overlay.CreateTextual(50, 720, 1366, eFontNormal, 51520,
      String.Format("room %d  mouse x%d,y%d   ft %d   tr %02d:%02d   pt %02d:%02d",
                     player.Room, mouse.x,mouse.y, FutureTime, BMin, BTimerSec,
                     PMin, PTimerSec)
                     );
    }
...
}

I just copied the timer (tics*min*sec etc.) to a var, starting reducing it by 1 in repeatedly_execute_always() if it was non-0.