Countdown timer GUI

Started by , Sun 04/03/2007 13:55:00

Previous topic - Next topic

Khris

Uh, GUIs are always displayed on top of everything else.
If the bomb is an object, you'll have to use another object to display to countdown.
If it isn't, you can use RawPrint.

jamesreg

I have used this code in my game but there is a problem it only shows a 9 second countdown how do i increase that

monkey0506

Well the first code snippet being this:

Code: ags
int countdown; 
bool countingDown;

// where you want the countdown to be triggered
countdown=400;//length in seconds*40
countingDown=true;
gCd.Visible=true;

//in repeatedly_execute
if (countingDown==true) {
countdown--;
lblCTD.Text=String.Format("Time remaining: %d seconds", FloatToInt(IntToFloat(countdown/40)));
if (countdown<=0) player.ChangeRoom(999); //the game over room
}


Offers a 10 second countdown. I guess that's the one you've used. It says right in the comments where it needs to be changed to increase the time though. The line "countdown = 400;" controls how long to run the countdown for. Changing just that we could do instead:

Code: ags
int countdown; 
bool countingDown;

// where you want the countdown to be triggered
countdown = 60 * GetGameSpeed(); // length in seconds * game speed
countingDown=true;
gCd.Visible=true;

//in repeatedly_execute
if (countingDown == true) {
  countdown--;
  lblCTD.Text=String.Format("Time remaining: %d seconds", countdown / GetGameSpeed());
  if (countdown <= 0) player.ChangeRoom(999); //the game over room
}


I replaced the instances of 40 with GetGameSpeed() above just in case you have a setting that will change the game speed from the default of 40 FPS. Beyond that I only changed the aforementioned line so that it now runs for 60 seconds instead of just 10. If you wanted to do minutes and seconds you could do:

Code: ags
int mins = 5;
int secs = 40; // replace with whatever time you want
int countdown = ((mins * 60) + secs) * GetGameSpeed();

// ...in rep_ex
mins = (countdown / GetGameSpeed()) / 60;
secs = (countdown / GetGameSpeed()) - (mins * 60);

jamesreg

Thanks,

got the timer working the way I wanted

one question how do i stop the timer when im done with it if they do the desired action before the countdown is completed
and how would I restart the timer if i need them to do a series of actions that would restart the timer with each action

monkey0506

#24
To disable the timer entirely you could change this line in rep_ex:

Code: ags
if (countdown <= 0) player.ChangeRoom(999);


To something like:

Code: ags
if (countdown == 0) player.ChangeRoom(999);


Then to disable the countdown you could just simply put:

Code: ags
countdown = -1;


And finally in rep_ex, before the other code:

Code: ags
gCd.Visible = (countdown > 0); // show or hide gCd based on the value of countdown


That way all you have to do is set the countdown timer to whatever you want it to be each time you need the action to start. Here's a revised version of the code:

Code: ags
int countdown = -1; // we'll use this as both our timer and our counting down flag

// where you want the countdown to be triggered
countdown = 60 * GetGameSpeed(); // length in seconds * game speed

//in repeatedly_execute
gCd.Visible = (countdown > 0);
if (countdown > 0) {
  countdown--;
  lblCTD.Text = String.Format("Time remaining: %d seconds", countdown / GetGameSpeed());
  if (countdown == 0) player.ChangeRoom(999); //the game over room
}

// disable the countdown
countdown = -1;


Edit: Nothing like a bit of self-promotion! :=

You can now check out the CountDown module to simplify the process! :)

jamesreg

Im using this script or a mod version with the timer being the amount of time I need for my game

I need to add five seconds to this timer every time a character does a specific act how would I do that?

monkey0506

If you're using the code that I just posted then you would just have to do:

Code: ags
// player triggers checkpoint
countdown += (5 * GetGameSpeed());

SMF spam blocked by CleanTalk