Godot Version
4.4.1
Question
I am making a simple save system, but i hit a major roadblock when i found out GDScript has no way of fetching the name of a variable. What i’m trying to do is to automate this with a function:
has_met = true
Save._save(“guy”, “has_met”, true)
But wrapping this with a function gets it value instead, writing “false = true” to the file.
Is there any simple way to do this? I have looked into dictionaries but that doesn’t quite seem to be the answer either.
I think dictionaries are absolutely the right way here.
If your goal is to create a save / load system, I think the best option would be to give each instance you want to save / load a function called save()
and load()
where save returns a dictionary of values you want to save, and load accepts that dictionary back, and re-assigns the variables if the dictionary is not empty.
Then have a piece of code that either finds all instances that implement these functions, or better yet, put all the instances you want to save inside a group.
There’s a nice explanation of how this can be done here: