save many variables as one

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

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?

:bust_in_silhouette: Reply From: jgodfrey

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…