Countdown Timer error [solved]

Started by arj0n, Fri 12/08/2011 09:39:06

Previous topic - Next topic

arj0n

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:


Code: ags

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


Code: ags

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

Wyz

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);
// ...
Life is like an adventure without the pixel hunts.

arj0n

Found it already but thanx anyway for the quick reply Wyz  :)

monkey0506

For the record there's also the Countdown module.. ::)

arj0n

Ow, didn't knew that. Thanx for the head-up monkey.

SMF spam blocked by CleanTalk