Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lordbry |
Hello all. I’m having a strange problem with saving game progress. I originally saved each variable separately to a file. That worked fine. There were SO MANY variables though, that every time I added a new one, or changed something around, it got too crazy to manage. So I tried to save an OBJECT instead. That way, I change the object class, and everything saves properly – in theory. It doesn’t work though. I’m missing a step somewhere and I hope you can help me with it. Here’s what I have:
Vars.gd:
extends Node
var MyVar = 0
func _init(_MyVar):
MyVar = _MyVar
Main.gd
extends Node
var oVars = preload("res://Vars.gd")
var MyStuff = []
MyStuff.append(oVars.new("XYZ"))
Save.gd
extends Node
onready var myAutoLoad = get_node("/root/Vars")
const FILE_NAME = "user://saves.json"
var env = {
"varObj": []
}
func saveAll():
env.varObj = myAutoLoad.MyStuff
var file = File.new()
file.open(FILE_NAME, File.WRITE)
file.store_string(to_json(env))
file.close()
Now when I look at what was actually saved, I see this:
saves.json
{"varObj": ["[Node:1355]"]}
I could have 1000 variables in there, and it still condenses them all into “Node:1355” instead of saving each variable in the object as a dictionary. Since it doesn’t save each variable independently, I can’t load it properly. UGH!
Thanks in advance for your help with this issue.