Hello All,
I am currently creating an adventure game and need some help. The game is fairly small and short (only about 7 rooms). I need help creating a timer. Basically, it starts at 3 minutes and counts down. At every 15 second interval, I would like the main character to say something. It would be great there is a way to create a visible countdown timer in the corner of the screen, but I also don't mind if the man character just says how much time is left. I would like the timer to span across all rooms and be constant, meaning, if the protagonist leaves room 1 with 30 secs left, he starts in room 2 with 30secs left. Lastly, I am also trying to figure out how to make objects and characters in the world affect the timer. For example, if the main character uses an item on a character, the timer will increase/decrease. For what I need, if the timer just increases with actions, that will be fine but if there is a way o do both, that would be great. If you have any questions for me, please do not hesitate to ask. And earl thanks for your help.
Quote from: LLPimpA on Tue 07/02/2012 11:53:02I need help creating a timer. Basically, it starts at 3 minutes and counts down.
Sounds like a job for the CountDown (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=39606.0) module!
Create a GUI with a label on it. Name the label
lblCountDown, and then add this code to your GlobalScript to use the module (make sure you import the module of course! ;)).
function game_start()
{
// called when the game starts, before the first room is loaded
CountDown.PauseWhileGamePaused = true; // pause the countdown if the user pauses the game
CountDown.TimesUpText = "The bomb went off, killing everyone! You lose..."; // text to display to user when the countdown runs out
CountDown.TimesUpAnnouncer = player; // use Display, not character speech
CountDown.ShowOnLabel = lblCountDown; // display the countdown timer on the lblCountDown label
lblCountDown.Text = "The bomb will go off in M minutes, S seconds..."; // set up the label format for the countdown
}
// wherever the timer starts:
CountDown.SetTime(0, 3); // 3 minutes, 0 seconds
// repeatedly_execute
if ((CountDown.RawTimeRemaining > 0) && ((CountDown.Seconds % 15) == 0))
{ // if the timer is running, and the second counter is exactly divisible by 15 (that is, every 15 seconds)
player.Say("Time is running out fast!");
}
With the information you gave, it's a bit hard to customize this exactly to your needs, but it should be enough to get you started.
As for increasing/decreasing the time, you can use CountDown.SetTime. Let me know if you need any help with it.