Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Fri 12/08/2011 09:39:06

Title: Countdown Timer error [solved]
Post by: arj0n on Fri 12/08/2011 09:39:06
I wanted to have the countdown (counting from 01:59 to 00:00) displayed in a label in a gui. So far I've got this:



// main global script file
int countdown;


function repeatedly_execute() {
if (countdown==0){
 countdown = -1;
}}
export countdown;


function repeatedly_execute_always() {
if (countdown > 0) {
countdown--;
String buffer;
int mins = ((countdown / GetGameSpeed()) / 60) % 60;
int secs = (countdown / GetGameSpeed()) % 60;
Ltime.Text=String.Format(buffer, "%02d:%02d", mins, secs);
}}



// room script file
import int countdown;
//int countdown;
//bool countingDown;

function room_FirstLoad()
{
countdown=4800;//length in seconds*40
}


When running the testgame I got an error:
---------------------------------------------------------------
Error running function 'repeatedly_execute_always':
Error: Null string referenced
---------------------------------------------------------------



EDIT:
Found it.
Removed "String buffer;" and "buffer" in "Ltime.Text=String.Format(buffer, "%02d:%02d", mins, secs);".

Sorry...It was to early in the morning for me to think clear I guess ;)
Title: Re: Countdown timer error
Post by: Wyz on Fri 12/08/2011 10:39:52
For the new style String in AGS you don't need string buffers any more. So this will work:
Quote
// ...
Ltime.Text=String.Format(buffer, "%02d:%02d", mins, secs);
// ...
Title: Re: Countdown Timer error [solved]
Post by: arj0n on Fri 12/08/2011 10:40:58
Found it already but thanx anyway for the quick reply Wyz  :)
Title: Re: Countdown Timer error [solved]
Post by: monkey0506 on Fri 12/08/2011 10:49:24
For the record there's also the Countdown module.. ::)
Title: Re: Countdown Timer error [solved]
Post by: arj0n on Fri 12/08/2011 12:30:18
Ow, didn't knew that. Thanx for the head-up monkey.