[solved] Player re-appear after game over


How do I prevent my player character from reappearing when number of lives reach zero ?

I have created a scene variable called PlayerLife and added the condition that if the value in the PlayerLife is <= (less or equal) to zero then the action should be to hide the player character.

This does work however, the player character reappears while the game is checking the variable

The only way that I can get it to work right now is by creating a Timer and then set it to 0.05 seconds and when this time has passed then show my Game over text, however, it doesn’t look good having the the Game over text appear so fast once the player run out of lives.

1 Like

You could add an animation or a black screen while it’s checking the variable or waiting for the timer


Thank you for the suggestion, however, there MUST be another way around this problem - I’ve spent a few hours searching the web and youtube for a solution, but cannot find one which involve multiple lives and what to do once the last life is lost.

So far the only solution to this problem would be if it was possible to test a variable BEFORE the game starts over after a life is lost.

Have you tried deleting the object? I don’t think it’d reappear after deleting

Maybe if its a global variable then its more important to the game or something? Im just guessing now but hou could try.

Yes I have tried that and also just hiding the object, however, the condition (PlayerLife = 0) have to be evaluated first and while this is happening the player character respawn and then vanish when the result condition finds that the value of/in PlayerLife is 0.

show the code for the timer GameOver, your condition is an AND so life must be <=0 and the timer greater thsn the time you specified

Thank you for your feedback.

I have tried removed the timer all together, however, the Player Character still shows up in the first frame when the game starts up again and then vanished immediately again (because of the condition (PlayerLife = 0)

The reason why I added the timer was that I have read from a tutorial that this is the to display a “Game Over”-text after some time has passed.

yes you can use a timer for a game over text i do that in my game.
If you could show all the events or share tje code to take a look we could do more than guessing :confused:

Here is a screenshot of my events:

How do I submit code ? - do I need to make a copy of the game.jason file or should I open the file and paste the content (that would be a lang post) ?

you can upload the json file to somewhere like MediaFire, Dropbox or other service like firefox send. It would be better of you zip all the folder containing your project and assets as with large code is difficult to see what happens if you can’t run the code.
For your code, make a backup of the .json file and try this after player life is 0 add another even but this time check it player life is > 0 then all the code below has to be a subevent of thsis event
i think this should work


I have tried the to do as you suggested and added another event to specify what to do if the PlayerLife variable is not equal to 0 and I did move the rest of my event under that event - even though I failed to see the point (however, this possibility had to be tried also) as the program already evaluate the PlayerLife variable to see if the conditions is false or true, so there is basically no need to tell it what to do if the result of the condition is false (ie. qual to 1 or -1) in this case.

I have also made a copy of my project folder - please feel free to grab it and have a look for yourself: http://www.mediafire.com/file/qjx8ple8qige47x/platform_tutorial.zip/file

the point was if alive run all the code of the game if not delete object and show gameover, the rest of the code won’t be executed.
If it doesnt work i guess there is a problem with the variable, will take a look

ok, found your problem it was here

added delete object player, the problem is that you set the checkpoint position to the player position, so it moves it there.
Another option is not to do this here but in other event


Thank you :hugs: it solved my problem - as long as there is only one life left !

This needs some tweaking, because if there is more than one life left the game won’t show the player and it also prevent the checkpoint from working, so I’m not sure that this is the optimum solution to the problem.

hi, no big deal
if player in collision with slug and om floor do -1 to playerlife
then do a subevent
playerlife >0 then do checkpointx ;checkpointy to player position
another subevent from collision event
playerlife <1 then delete player


This time you nailed the problem - very well done indeed :+1:

However, I don’t think it is necessary to write so much code as your solution suggest, because all I had to do was adding a sub event with the condition:

So I guess that adding any more than that is overkill, because the only time this code will ever fire is when the PlayerLife is 0 or less.

So once again I’d like to say a big thank you for helping out - I guess we both have learned something from the experience and we can hope that other can make you of this example if they ever run into a similar problem with a game restarting after game over.

1 Like