Show Timer in GUIs

Started by Joe, Mon 28/08/2006 15:29:14

Previous topic - Next topic

Joe

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.
Copinstar © Oficial Site

SSH

This is a beginners question really: in repeatedly_execute:

yourGuiLabel.Text=String.Format("%d", timer_value);
12

strazer

#2
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.

Joe

Thankyou for answering

And how would you do that?
Copinstar © Oficial Site

strazer

For example:

Code: ags

// 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
  }

}


Code: ags

// main script header

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


Code: ags

// some script

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


SMF spam blocked by CleanTalk