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 ;)
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);
// ...
Found it already but thanx anyway for the quick reply Wyz :)
For the record there's also the Countdown module.. ::)
Ow, didn't knew that. Thanx for the head-up monkey.