This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Sorry for bad English. I try to describe my problem.

I make a sign-up page for my game and set a data at global singleton and save that when player start game at first time.

var user = {
    name = null,
    money = 1000,

I make a remove button for delete data, If the player want to start new game again.

func user_remove_data():
    var dir =

Everything is OK. But my problem is:

  1. Player sign-up (write name).
  2. Save data and start playing.
  3. For example buy something and money become to 700.
  4. Come back to sign-up and remove name (game data)
  5. Write another name and start new game
  6. Money is NOT 1000, money is 700.

I add a for loop to func user_remove_data() for reset data

for data in _global.user:
    if data == 'name':
        _global.user[data] = null
    elif data == 'money':
        _global.user[data] = 1000

I want to know that is there a better way to reset data at memory or my way is okey?

in Engine by (54 points)

1 Answer

+1 vote
Best answer

If you make your 'singleton' like this:

var user = initUser()

func initUser():
    return { name = null, money = 1000 }

func resetUser():
    user = initUser()

you will have initial values for user var in just one place. This is good because if you'll want to change initial values you'll only need to do this in one place.

resetUser() can be called fron any script you want, no need to write reset code every time.

by (2,308 points)
selected by

Thank you!!!

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.