How do use "queue free" but on a value that isn't a node

: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 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.

:bust_in_silhouette: Reply From: AlexTheRegent

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

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

Spafnar | 2021-01-01 08:59

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).

Spafnar | 2021-01-01 09:24

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

AlexTheRegent | 2021-01-01 12:44

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!

Spafnar | 2021-01-01 17:59