visible 30 second countdown...?

Started by YotamElal, Mon 02/05/2005 12:02:17

Previous topic - Next topic

YotamElal

what is the best way to do a visible 30 second countdown...? (in the background?)

Ashen

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:

Code: ags

// 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.
I know what you're thinking ... Don't think that.

YotamElal

instead of a textbox in a gui.
I want to have an a character of mine displaying the countdown (in the background)

Ashen

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:
Code: ags

// 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);

I know what you're thinking ... Don't think that.

YotamElal


guybrush

But how to do non-visible countdown?
SPY FUNCTION-- My first game
C O M I N G   S O O N !

Scummbuddy

just set a timer in your code, in whatever room you want.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

SMF spam blocked by CleanTalk