Changing to the last screen using a buttton

Hi all, I am attempting to make a game where you dodge blocks and progress through levels. I am attempting to make a button on the game over screen to resume from the last level you died in. For example, you die on level 3 and go to the game over screen. I am trying to make a reset button so you could then press that to restart the level. Currently I am having some problems, however. I cannot figure out what is going wrong in my code because it makes sense in my head. However(without errors) it does nothing. Here is my project link: Thanks in advance!

Edit: My code for changing scenes is found in the end-game entity. This is also found in the player collision script.

Hi @Magifire,

Are you still experiencing this issue? After I press Reset on the game over scene I am redirected to a different scene. Though it seems there are multiple scenes loading? Make sure that the old hierarchy is deleted before adding the new one.

1 Like

Yes, I have it so that when you press the reset button you are placed in level 5 as a test. However, this is not what I wanted. I wanted to take the information from my end entity, used to bring you to the next level when you completed the previous, and use it so my reset button knows what levels you have beaten and what levels you haven’t. This way when you die and press the reset button it will bring you to the scene you just were trying to complete. I was wanting advice on how to accomplish this because the previous things I have tried did not work.

Without seeing what you have tried, it be very difficult to advise. Maybe make a small project to show the original code so people can see if there are any issues?

… There! This is a simplistic version of this ready to insert the needed code. I cannot figure this out, however. What I am needing is an variable way to obtain what scene 1’s name is and to bring that info to my button script so it can know that when you press it to move you to that scene. This way eventually when I put it into my full game, no matter where you are in the levels, for example if you were on level 3 and died you would press the button and go back to level 3. I have tried a couple things already, however I keep getting stuck on attempting to get the scene’s name and move it over to the game over scene for usage in the button script. To start the game, press enter. Move left and right with the left and right keys.

You can do this in several ways:

You can make the button itself change the scene on the ‘click’ event.

Or you can have the button fire an event with the scene name so that another script can change the scene.

Here’s an example of your project with a modified changing-scenes.js file that changes scenes on the click event of the button:

THANKS! It worked perfectly! I just had to make a new game over scene for each level. Thanks for helping me.