what is the best way to do a visible 30 second countdown...? (in the background?)
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.
instead of a textbox in a gui.
I want to have an a character of mine displaying the countdown (in the background)
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);
Thank You...
Works Great!
But how to do non-visible countdown?
just set a timer in your code, in whatever room you want.