Lives Aren't Reducing

I'm trying to implement a lives system into a simple arcade platformer I am making and when I die, it doesn't subtract the number of lives I have.

All of this is in obj_lives

Here is the Create Event
Code:
///Score, Lives etc

global.life = 3
And here is the Draw Event

Code:
draw_set_halign(fa_left);
draw_set_valign(fa_middle);
draw_set_color(c_white);
draw_text(64,64,global.life);
And here is the code for when one of enemies collides with my main character

Code:
if( global.life > 0){
    global.life -= 1;
}
game_restart()
If there is something wrong or something I forgot to put in, just let me know because i know I am missing something.
 
A

ajan-ko

Guest
if( global.life > 0){
global.life -= 1;
} else
game_restart()

good luck
 
G

Guy Danino

Guest
Game reatart will recreate all the objects and rerun their create event. which means the life counter goes back to 3.

Depending on other mechanics in your game, you can either:

1. make obj_lives persistant (by checking the box in the object editor), which mean he should keep its changed variables even through a restart. after that, restart only the room and not the game.

2.drop game_restart() and instead, initialize the player x and y and respawn the enemies. write a script with a bunch of instance_create lines. of course, you should run a check for each to see if it has been destroyed or not. for example:

If (!instance_exists(obj_skeleton_enemy)
Instance_create(500,1040,obj_skeleton_enemy;

But that will be a lot of work for each room you create.


Hope this helps!
 
A

ajan-ko

Guest
Game reatart will recreate all the objects and rerun their create event. which means the life counter goes back to 3.

Depending on other mechanics in your game, you can either:

1. make obj_lives persistant (by checking the box in the object editor), which mean he should keep its changed variables even through a restart. after that, restart only the room and not the game.

2.drop game_restart() and instead, initialize the player x and y and respawn the enemies. write a script with a bunch of instance_create lines. of course, you should run a check for each to see if it has been destroyed or not. for example:

If (!instance_exists(obj_skeleton_enemy)
Instance_create(500,1040,obj_skeleton_enemy;

But that will be a lot of work for each room you create.


Hope this helps!
Or just room_goto()

Code:
if( global.life > 0){
global.life -= 1;
} else
room_goto(yourroomname)
 
A

ajan-ko

Guest
I didnt program that, but when he collides with the player it resets the level like nothing happen
ah, yes, you need invisibility frame when you get hit, so it's like this

put this code on player collision
Code:
if( global.life > 0 and invis<=0 ){
    global.life -= 1;
    invis=90; //3 second invisibility
} else {
    room_goto(yourroomname)
}
put this code on player create event
Code:
invis=0
and finally add this code on step event
Code:
if (invis>0) invis--
OR you simply just use destroy on your enemy.

put this code on your player colision
Code:
if( global.life > 0 and invis<=0 ){
    global.life -= 1;
    with (other) instance_destroy()
} else {
    room_goto(yourroomname)
}
 
Top