Can you reset a scene which also resets global/Autoload variables?

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

Hi,

I have a autoload global.gd file with a variables: gold, mana, hp, etc. When the player dies I want to be able to reset to the beginning of the game with the default values I placed in the code?

I tried: get_tree().reload_current_scene() but it won’t change the global.gd variables. Is this possible to reset autoload/global variables?

Thanks!

:bust_in_silhouette: Reply From: coffeeDragon

As far as i know, it’s not possible to do that.
In fact I hope that such a thing is not possible, as it would’ve strange consequents, like what happens if an other file tries to access that information in that moment.

I would suggest that you save player specific vars in the player node/object.
But if you want to do it in a global object, you could just create a reset function, allà:

func reset():
   health = deafaultVal
   mana = defaultVal
   etc

And just call that, instead of using var mana = defaultVal