0 votes

I have many variables in a script for the different nodes is there a way to save them all together?
I know how to save with this:

func save(content):
    var file = File.new()
    file.open("user://save_game.dat", File.WRITE)
    file.store_string(content)
    file.close()

func load():
    var file = File.new()
    file.open("user://save_game.dat", File.READ)
    var content = file.get_as_text()
    file.close()
    return content

but I have to do this with each variable to save is there a way to include many variables or save all the variables of the nodes in a faster way? that is to say, save all the variables in a line without having to go one by one.
I could use for for a loop, but how?

in Engine by (182 points)

1 Answer

+3 votes

I'd recommend placing all of the variables you want to save/restore in a single dictionary and then manipulating/saving/restoring that instead of managing individual variables...

by (10,866 points)
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.