My Label text isn't resetting upon the game ending

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spafnar

Hello, so I have a separate code for this question that increases difficulty (mob spawn and speed among other things.) And the two are unrelated, because it was just easier for me to code. The code in question is as simple as:

func _on_DiffTimer1_timeout():
GlobalSignals.level += 1
$Level1.text = "Level: " + str(GlobalSignals.level)

With the (autoloaded) GlobalSignals variable “level” as 1.

var level = 1

When playing it works great and I made the “DiffTimer1” match the wait time (25 seconds) of the previous progressive difficulty scripting I mentioned earlier, but that isn’t important. While playing, The label goes from “Level 1” then 25 seconds later “Level 2” , etc. perfectly fine every 25 seconds, but after dying, going back to main screen, and hitting to start to begin a new game, the level text stays as "Level: " and then whatever the previous game ended on. If you’re curious I do have the $DiffTimer1.start() and $DiffTimer1.stop() at both my new_game and game_over functions.

Well that makes sense… your autoloaded scene is forever in the bg, and so the variable sticks.

Not sure that’s the best practice, but I’d suggest adding a reset_game_globals() function, which init all the relevant values that you want to init on a new game.

putskan | 2021-01-02 19:47

:bust_in_silhouette: Reply From: abelgutierrez99

Hello, I’m new to Godot,
Try to do: when you die, in that function, write GlobalSignals.level = 1