I have a simple platformer game which swaps between two scenes. The first scene is the main menu and contains a start button and a label with the highscore. The second scene is the game scene where the player has to avoid dying, and once he dies the scene switches back to the main screne. I'm using v4.2, and I'm using the switch_to_file() method to do that. Although the two scenes switch back and forth exactly as I want them to, they don't "update" correctly. The highscore on my main menu is displayed correctly (as it is updated within the player death function), but the score counter within the game remains the same. How can I "reset" the entire scene (so the counter starts at 0 again)?
#Switching between two scenes
6 messages · Page 1 of 1 (latest)
try get_tree().reload_scene()
if that doesnt work, then you'll probably have to manage the score in code
which you should be doing anyway, by having an initializiation function that runs in the _on_ready() function of the scene
If I understood it correctly, you can have a singleton in here. It has a variable called highscore which stores and a variable called score which has the current score in the new play session.
Once the player dies, if his score is greater than the highscore then the highscore stores the score value, and the score resets back to 0.
Then in the main menu you just have to show this highscore variable.
ye, I'm using a singleton already (I believe it's called a singleton? Well, it's a script that I put into autoload), but I forgot that I can just reset the score to 0 in the player death function as well XD