Mac OSX GML: hp bar using hp sprites not working

C

chessmates

Guest
hi, im fairly new to game maker studio, and im having trouble with my healthbar. i coded it myself, but i cant get it to work, when i try to run the game i get an error upon running.

this is the error message:
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_hpbarcorridor:


DoAdd :: Execution Error
at gml_Object_obj_hpbarcorridor_Create_0 (line 2) - sprite_index = asset_get_index("spr_hpbar" + state);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_hpbarcorridor_Create_0 (line 2)


and this is the code it says is wrong, both the step and create event:

step:
state = global.hp;
sprite_index = asset_get_index("spr_hpbar" + state);


create:
state = global.hp;
sprite_index = asset_get_index("spr_hpbar" + state);

 

Simon Gust

Member
You can only combine strings with strings. Not strings with reals. global.hp is a real and you need to convert it to a string before combining it with spr_hpbar.

Code:
state = string(global.hp);
The rest of the code looks fine to me.
 

TheouAegis

Member
Just how high can global.hp go? That's potentially a lot of pointless sprites and wasted texture page space.
 
Top