Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: YotamElal on Mon 02/05/2005 12:02:17

Title: visible 30 second countdown...?
Post by: YotamElal on Mon 02/05/2005 12:02:17
what is the best way to do a visible 30 second countdown...? (in the background?)
Title: Re: visible 30 second countdown...?
Post by: Ashen on Mon 02/05/2005 13:15:30
Very generally:
Create a GUI, 'Normal' visibility, with a label to display the countdown (or put it on the STATUSLINE as I have). Create an int to track the countdown. Then:


// Either in room script, or global script, depending on where/when you want the timer to be active
int count = -1;  // So 'if (count == 0) condition won't be triggered too early. See below
string temp;
// If in Global, remember to Export/Import them.

// Then, in rep_ex (again, room or global, depending):
if (count > 0) {
  count --;
  StrFormat (temp, "%d", (count/40) + 1);
  // The '+1' is needed since AGS rounds down. Otherwise, the countdown would start from 29, and spend a second on 0 before timing out.
  SetLabelText (STATUSLINE, 0, temp);
}
else if (count == 0) {
  SetLabelText (STATUSLINE, 0, "0");
  Display ("Time out! You lose!");
  // Or whatever you want to happen
  count = -1; // So this won't be called over and over
}

// Finally, wherever you want the countdown to be triggered:
count = 1200; //30*40 (seconds * gamespeed)


Like I said, though, this is very general. If it's not what you want/need, ask again with more details.
Title: Re: visible 30 second countdown...?
Post by: YotamElal on Mon 02/05/2005 19:57:33
instead of a textbox in a gui.
I want to have an a character of mine displaying the countdown (in the background)
Title: Re: visible 30 second countdown...?
Post by: Ashen on Mon 02/05/2005 21:21:57
You just want the character to be counting down in the background, rather than waiting for the player to ask them? Then change the SetLabelText () commands to DisplaySpeechBackground (). You may also want to add an AnimateCharacter(), since DisplaySpeechBackground () doesn't run the characters talking view.

That should do it, anyway. An other way would be:

// Either in room script, or global script, depending on where/when you want the timer to be active
int count = 30;
string temp;
// If in Global, remember to Export/Import them.

// Then, in rep_ex (again, room or global, depending):
if (IsTimerExpired (1)) {
  if (count > 0) {
    count --;
    StrFormat (temp, "%d", count);
    DisplaySpeechBackground (COUNTER, temp); // Where 'COUNTER' is the script name of the character
    // Again, you might want an 'AnimateCharacter' command here
    SetTimer (1, 40);
  }
  if (count == 0) {
    Display ("Time out! You lose!");
    // Or whatever you want to happen
  }
}


// Finally, wherever you want the countdown to be triggered:
DisplaySpeechBackground (COUNTER, "30");
SetTimer (1, 40);

Title: Re: visible 30 second countdown...?
Post by: YotamElal on Tue 03/05/2005 19:40:30
Thank You...
Works Great!
Title: Re: visible 30 second countdown...?
Post by: guybrush on Thu 05/05/2005 19:53:57
But how to do non-visible countdown?
Title: Re: visible 30 second countdown...?
Post by: Scummbuddy on Thu 05/05/2005 20:06:36
just set a timer in your code, in whatever room you want.