• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Player can't die

P

Pedau666

Guest
I made a health system like in Zelda, where player have hearts that have two parts. After implementing this code I constantly get a crash after player gets to 0 health. Here is the code, can you guys help?

PLAYER BEGIN STEP EVENT
if (o_player.hp <= 0)
{

instance_destroy();

}

HEALTH DRAW GUI EVENT
///draw heaarth
var width = (display_get_gui_width()) - (display_get_gui_width()/1.65)
var xx = width - 70 * 10
var yy = 35
var xempty = 0
var yempty = 0
var xfull = 0
var yfull = 0
var xhalf = 0
var yhalf = 0
o_player.maxhp = clamp(o_player.maxhp, 6, 40)
o_player.hp = clamp(o_player.hp, 0, o_player.maxhp)
//empty
repeat(o_player.maxhp/2)
{
if xempty == 65 * 10
{
yempty = 65
xempty = 0
}
draw_sprite(s_heart_empty, 0, xx + xempty, yy + yempty)
xempty += 65;
}
//half
repeat(floor(o_player.hp/2) + frac(o_player.hp/2) * 2)
{
if xhalf >= 65 * 10
{
yhalf = 65
xhalf = 0
}
draw_sprite(s_heart_half, 0, xx + xhalf, yy + yhalf)
xhalf += 65;
}
//full
repeat(floor(o_player.hp/2))
{
if xfull >= 65 * 10
{
yfull = 65
xfull = 0
}
draw_sprite(s_heart_full, 0, xx + xfull, yy + yfull)
xfull += 65;
}
 

hogwater

Member
You appear to be using "o_player.hp" within the player itself to reference variables, which you don't do. Within the object, you only need to use "hp" alone.
 
Top