Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Joe on Mon 28/08/2006 15:29:14

Title: Show Timer in GUIs
Post by: Joe on Mon 28/08/2006 15:29:14
Hello everyone

Im making a game which needs to show a timer in a GUI.
I know how to set the timer, I know how to give orders when the timer expires, but I don't know how to show it in a GUI.

Does anybody know how to do?

Thankyou.
Title: Re: Show Timer in GUIs
Post by: SSH on Mon 28/08/2006 15:59:44
This is a beginners question really: in repeatedly_execute:

yourGuiLabel.Text=String.Format("%d", timer_value);
Title: Re: Show Timer in GUIs
Post by: strazer on Mon 28/08/2006 16:22:31
SSH, I think he's talking about the built-in timers.

There's no GetTimer function, so you need to script the timer yourself using variables if you want to access its current value.
Title: Re: Show Timer in GUIs
Post by: Joe on Mon 28/08/2006 19:33:40
Thankyou for answering

And how would you do that?
Title: Re: Show Timer in GUIs
Post by: strazer on Tue 29/08/2006 01:57:49
For example:


// main global script

int MyTimer = -1; // define timer variable, initially off
export MyTimer; // export variable for use in room scripts

function repeatedly_execute() { // gets executed every game loop

  if (MyTimer > 0) { // if timer is on
    MyTimer--; // decrease timer by 1 game loop
    YourGuiLabel.Text = String.Format("%d", MyTimer); // display its value on your gui label
  }
  else if (MyTimer == 0) { // aka IsTimerExpired

    // do stuff

    MyTimer = -1; // turn timer off
  }

}



// main script header

import int MyTimer; // import variable for use in room scripts



// some script

  MyTimer = 400; // aka SetTimer; 40 game loops = 1 second