Player Death not working right.

Good evening all, It’s me again.

I’ve got a couple of problems and I have scoured the web trying to find the right code to fix it. Obviously I couldn’t find anything.
I have porgrammed in that when my playership’s life reaches zero, it is deleted and replaced by and explosion animation. At this point, a “Press Spacebar to continue” object comes up, the scene pauses, and waits for user to hit the spacebar. Now, what is supposed to happen is the Continue text goes away, a new playership is spawned at x;y, the Score carries over, and the Players lives are reduced by one, Or if applilcable, the Bonus lives are to be reduce by one. Bonus lives taking priority over the normal player lives, and/the emeny creation timer resets to clear the screen so the player doesn’t get swarmed on spawn.

Now in the code in the code, I have(Or at least I think I have) set the program to check to see if there are any Bonus lives and if there are to subtract one. If there is not, it auto kicks over and checks to see if and how many normal lives are left. If there are normal lives, it subtracts one. If there is not, it plays an end game sequence that results in a Game over animation and the Restart" spacebar text. At the Game over screen, hitting the spacebar is supposed to reset the screen 100% back at the current scene/level with a zero score and 3 normal lives.

The only part of this that works is when “reset” spacebar text pops up, after that, nothing responds. Hitting the spacebar does nothing. At one point(And I had to take the Do -1 Playerlives/Bonuslives out of the code. instead of it removing just one live of either of the lives, it keeps reducing lives into the -#'s. At one point I had Negative 6000+ lives.

This of course is not the only issue I have having, but I’ll work on this one in this post. Will post anouther for the other issue I am having. If you need me to send you a .zip file of everything so you can see where my stupid mistakes are let me know. Below is a SS of just the Player Death section of my code.

Help please. I’m running out of patience and beer. :confused:

The order of events is important. You should not delete the playership BEFORE using anything to do with it. Or in other words, delete the playership at the end of every condition and event in. At the moment, AstXP cannot spawn at playership.X() because playership is not existing.

Also, why should bonus lives be > player lives? It should be that bonus lives are subtracted before normal live (if I am understanding you correctly?). So, you need to first check has the player got any bonus lives, if yes, subtract one and then you are done. If no, check for normal lives and subtract one. If the total left is = 0, then do your end of game thing, if not, make a new ship and carry on. I put some pseudo code following this that you can hopefully follow.

Do = 0 to variable(done).

If(BonusLives > 0)

Take away one bonus life
Do =1 to Variable(done)

If ALL conditions are true
If(lives > 0)
if(done = 0)

Take away one life

If(lives = 0)

Do playerdeath event

There is another logic error in your code, I guess you misunderstood how sub-events works:

Event 81 ...Event 81.1 ......Event 81.1.1 .........Event 81.1.1.1
In this form, the event 8.1.1.1 will be executed if event 8.1.1 is fulfilled, but it’s impossible, because if the event 8.1.1 (Variable BonusLives > 0) is fulfilled, then the event 8.1.1.1 (Variable BonusLives <= 0) will not be satisfied.

You should have something like this:

Event 81 ...Event 81.1 ...Event 81.2 ...Event 81.3
Every sub event as a child of the first one.

Ok, so Instead of using Sub-events I make a new event, then add as many Child events to the Main event as I need? None leadingh off anything excapet the main event?

Main event: Do = 0 to variable(done).

…Sub event 1:
If(BonusLives > 0)

Take away one bonus life
Do =1 to Variable(done)

…Sub event 2:

If ALL conditions are true
If(lives > 0)
if(done = 0)

Take away one life

…Sub event 3:

If(lives = 0)

Do playerdeath event

Ok, I think this is right. The problem now, when player ship dies, all lives are removed not just one.

Much better :slight_smile:

I think every live is removed because the PlayerHP is still <= 0, maybe you could “refill” the PlayerHP variable (PlayerHP = initial HP value) in the same event where you remove the live.

Tip 1: Try to move the event 81.2 over the 81.1, otherway, if you have BonusLive = 1, with the event 81.1 you set BonusLive = 0, and immediately the event 81.2 is executed and do -1 to PlayerLives.
Tip 2: In the event 8.2 is unnecessary the “AND” advanced condition (is useful inside “OR” and “NOT” conditions)
Tip 3: I think is unnecessary delete the object Plashership again in the sub-event 81.3, because is a child of 81, so 81 already deleted it.