+1 vote


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: gettree().reloadcurrent_scene() but it won't change the global.gd variables. Is this possible to reset autoload/global variables?


in Engine by (61 points)

1 Answer

+2 votes
Best answer

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

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

by (264 points)
selected by
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.