Why var created in create event not being found in draw??

T

Thiago Sabin

Guest
I really searched and found no solution for this simple problem, i must be missing something simple...

In the create event of my object im doing this:

var hp = 10;

Then in the draw event im trying to draw a bar with that var like

draw_rectangle( -50, -40, 100/global.slime_max_hp*hp-50, -30, 0 );

And the draw event is not finding that var... i really don't know what to do...

Error:

FATAL ERROR in
action number 5
of Draw Event
for object slime:

Variable slime.hp(100005, -2147483648) not set before reading it.
at gml_Object_slime_DrawGUI_5 (line 1) - action_draw_rectangle( -50, -40, 100/global.slime_max_hp *hp-50, -30, 0 );
 

mar_cuz

Member
when declaring var it is a local variable for that event only and can't be read by other events. Its like a throw away variable you use only for that event. You don't have to use var in the create event anyway just do hp = 10; in the create event and other events can use it
 
T

Thiago Sabin

Guest
when declaring var it is a local variable for that event only and can't be read by other events. Its like a throw away variable you use only for that event. You don't have to use var in the create event anyway just do hp = 10; in the create event and other events can use it
Got it, really thanks!
 
Last edited by a moderator:
Top