Hey there, I've been looking around for a way to set a coutner up in a room. I want it to initially display 3 minutes in the top right hand corner and count down to 0, after which it will display a message telling you that you have died unless you have completed the puzzle.
I think I may have the timer sorted out:
if (interface==COUNTDOWN) {
int counter = 300;
while (counter > 0) {
counter =-1;
}
But how do I get it to check whether a puzzle is completed and if not display the end result of GAME OVER, and how do I keep the time displayed to the user?
Thanks
If you still want controls and other things happening during the countdown, you can't put the decreasing part within interface_click() (if you really want to start it via clicking on an interface :p), just put it into repeated_execute:
if (counter>0) {
counter -=1;
if (counter==0) {
// put whatever you want to happen when the counter expires HERE
}
}
Thanks Gil, but how do I show the counter on screen?
Create a GUI label in the place where you want it displayed. Then, in repeatedly_execute:
string buffer;
StrFormat(buffer, "%d:%02d", counter / 60, counter % 60);
SetLabelText(GUI, OBJECT, buffer);
if you're using 2.6 SP1 then % won't work, so instead do this:
StrFormat(buffer, "%d:%02d", counter / 60, counter - ((counter / 60) * 60));
I must be doing something wrong, its been a while sicne ive scripted in AGS, heres my code:
function repeatedly_execute() {
int counter = 300;
if (counter>0) {
string buffer;
StrFormat(buffer, "%d:%02d", counter / 60, counter - ((counter / 60) * 60));
SetLabelText(COUNTDOWN, 0, buffer);
counter -=1;
if (counter==0) {
QuitGame(0);
}}}
And I only want it to start counting down when the script is called
Delete the "int counter = 300;" line - it is resetting the counter to 300 every time repeatedly_Execute is called.
Instead, put:
int counter = 0;
at the top of the global script.
Then, when you want to start the counter ticking, simply do:
counter = 300;
Thanks... but it's counting down incredibly fast, I want the time to be 3 minutes so what do i need to set it as?
sorry for beign a pain :P (i ares teh 1337 n00b :S.... kinda)
The counter is in game loops, which happen 40 times per second. So 3 minutes would be:
60 * 3 * 40 = 7200
i feel really bad for this now, i'm sorry, everythings great and all except for the fact that it is displaying the seconds, how can I set the timer so it displays 3:00 as in 3 minutes and count down in seconds.
Sorry for the long posting discussion, i'm trying to get all thsi done ASAP so it can be beta tested by someone.
this will probably need two labels, then.
two if statements, one within the other. the outer one will control the minutes, and the within if statement will do the seconds.
so itll start, by thinking.
ok, its 3 mintues, then to the 2nd if, subtract one from the first label, do the 59 second countdown on the second label, return to the outer shell, ok its 2 minutes, then to the second if, and so on.
Since the counter is in game loops, you need to divide by 40 to get seconds:
string buffer;
int seconds = counter / 40;
StrFormat(buffer, "%d:%02d", seconds / 60, seconds - ((seconds / 60) * 60));
SetLabelText(COUNTDOWN, 0, buffer);
Thank you so much, it works like a charm