i would like to create a simple lives counter. for example a lives counter at the top left of the screen for three lives. once a character dies the counter goes down one and when they run out of lives the game goes back to the start screen.
i’ve followed the tutorial for the coin counter and guess this is basically the same set up with a global variable so it can go from scene to scene. however, i i have no clue how to set up the events for subtracting from the counter with each life lost / respawn?
thanks in advance!
Just Do -1 to lives. Select the subtraction opration instead of addition.
If life <=0 : Do -1 to lives and Do = 100 to life.
Something like this.
ddabrahim- thank you for the info!
here is the events i have so far. the counter shows up on screen but has a value of 0 if the character dies or not. the main thing i dont understand is connecting the counter to the player?
so far i guess the big questions are:
how do i get my counter to read 3 lives (not zero as it says currently)?
and how do i connect the death of my character to the subtraction of a life?
then once the character has no lives how do i make it go to the start screen?
thanks in advance!
Something like this should work…
Just want to point out, the variable Lives is Global so in the expression use GlobalVariable(Lives) instead of Variable(LIves) as BWPanda shown.
BWPanda- thank you for posting that! that was hugly helpful. i had a few other things arranged with the character dieing, but once i organized it and added in the events you posted it worked perfect! thanks you very much!
ddabrahim- thanks! i probably would have missed that haha
my only question now is since there are many things that can kill the player (falls, other enemies for example) do i add each collision in this event so it counts on the life counter or do i copy and paste this for every enemy? which is the best solution, is there a way to group all things that can harm and do one event that covers them all? either way, i’m thrilled this is working now!! thanks
One thing you should definitely do (if you haven’t already) is to create an object group (called, for example, ‘enemies’) and add all your enemy objects to it. Then you can just test for a collision between your player and the ‘enemies’ group, take off a life, etc., and that’ll save you doing the same thing over and over again.
If you then want to add other conditions, such as falling off the screen, you can add an ‘or’ condition that’ll check for a collision with enemies OR player falls off the screen, then you’ll only need the life counter action in one place, rather than copying and pasting multiple times.
BWPanda - i did not know about that! but that was exactly what i was looking for, thanks again for all the help!
It does not work for me. I have this but the life counter never goes down to zero
Is Jugador constantly colliding with Enemigo? If yes, then that’s why. Because using the Trigger Once condition, the collision need to stop and happen again to trigger the action again.
Use a timer if you want to reduce the life slowly if the player constantly colliding, something like this.
[code]If Jugador colliding with Enemigo
Start timer “damage_timer”
If “damage_timer” > 1 second
Do -1 to Global variable Vida
Reset the timer
If Jugador is NOT colliding with Enemigo
Reset timer “damage_timer”
Pause timer “damage_timer”[/code]