Problem displaying Health points on GUI.

Started by Rik_Vargard, Mon 12/04/2004 17:27:39

Previous topic - Next topic

Rik_Vargard

Here's the error message. The white line is the line with the error.
I made a new GUI (4) where the points should be displayed on object 1, wich is a label with no text.
I'm lost... help!  :P

error (line 14): undefined symbol 'health'

function game_start() {
 string Health;
 SetGlobalInt(10,100);
 if (GetGlobalInt(10)>0) {}
 else Display ("You are dead");
}

function repeatedly_execute() {
 StrFormat(Health,"%d", GetGlobalInt(10));
 SetLabeltext (1,4,Health);
}

Thx for any comment! :)

Scorpiorus

The first declaration of Health is made within a function body so it's a local string variable, so you can't use it in another function. You can either declare that string variable within repeatedly_execute or declare a global string outside all functions.

Variant a).  Repeatedly_execute's local string:

function repeatedly_execute() {
string Health;
StrFormat(Health,"%d", GetGlobalInt(10));
SetLabeltext (1,4,Health);
}

Variant b) A global string variable

string Health;

function game_start() {
SetGlobalInt(10,100);
if (GetGlobalInt(10)>0) {}
else Display ("You are dead");
}

function repeatedly_execute() {
StrFormat(Health,"%d", GetGlobalInt(10));
SetLabeltext (1,4,Health);
}

~Cheers

Rik_Vargard

Hey, thx for your help... but :P... now I got this errors:

When I used variant a:

Undefined token: 'SetLabelText'

When I used variant b:

Undefined Symbol 'Health'

Note: I have a GUI4, with object1 (label) with no text on it where this should be displayed.

Thx a lot!

TerranRich

Did you follow the Beginners' FAQ? If not, please do so before posting. If so, it doesn't look like it. :)
Status: Trying to come up with some ideas...

Rik_Vargard

I did read it. Before asking I always loose a lot of time trying to find out by myself and mess up a lot of things in my game.   :P

There was just a little error I did and found out just right now: it's first GUI, then object.. so it's 4,1,... and not 1,4...
And I reverted it by error because I based myself on a tutorial found on the site where they say "Object, GUI" instead of "GUI,Object", like it should be. So now you know it all...  ;)

Anyway, Scorpiorus, thx for your help, it works cool & fine, now!

SMF spam blocked by CleanTalk