+1 vote

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

Thanks!

in Engine by (61 points)

1 Answer

+1 vote
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
   etc

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

by (256 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 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 webmaster@godotengine.org with your username.