0 votes

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 onDiffTimer1_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 newgame and gameover functions.

Godot version 3.2.3
in Engine by (53 points)

1 Answer

+1 vote
Best answer

Singletons are never unloaded/reset. You need to reset your singleton values on new game manually (GlobalSignals.level = 1 when new game is pressed).

by (1,646 points)
selected by

Awesome! Good to know, I've been trying to figure this out for a while. Had no idea it was so simple.

Actually.. It still doesn't seem to be working. I put the (GlobalSignals.level = 1) in both my newgame and gameover function just to be safe, but I am still having the same issue. After getting to level (x), dying, and starting a new game, the label still says level (x).

If your game menu scenes are one scene, you need to manually update label text on new game too.

Ah there, it is. After I put in the (GlobalSignals.level = 1) in my HUD's startbuttonpressed function, it worked halfway, because It would still start a new level with the previous game's level, but after going 25 seconds and leveling up, it would adjust itself correctly. All I did to combat this was simply put a $Level1.text = "Level 1" in the same function and everything seems to be working perfectly. Thanks a lot for your help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.