I'm kind of stumped. I've followed and adapted the save system from this.
To phrase the problem, I'm unsure how to load the dictionaries back into the original variables. Most likely easier to explain the problem as you see it.
# This would be "GlobalData"
onready var KEY = name
# Stats dictionary
var stats:= {
"health" : 75,
"stamina": 25
}
# Meta Dictionary
var meta:= {
"testing": "I'm a totally random thing",
"testing2": 2002,
"date": "Thursday, 2020-08-20, 20:12"
}
# Load both into array to iterate through upon saving
var list = [stats, meta]
func save(save_game:Resource):
var i = 0
for element in list:
# Make a unique key based on iteration
var temp:String = KEY + String(i)
# Store data to key
save_game.data[temp] = element
i = i+1
func load(save_game:Resource):
var i = 0
# === Where the error lies === #
# While saving works fine, I cannot use the list array to push content back into the original dictionaries
# If I targeted the dictionary by it's variable, then it got applied.
for element in list:
var temp:String = KEY + String(i)
element = save_game.data[temp]
i = i+1
So, my question relies in "how do I re-apply the loaded data?". Do I have to write the list into a way, that it would store the dictionary name too? Or is it possible to somehow call the name of the element to get it to target the original variable/dictionary?
PS. Don't ask why I'm not using i++ or i+=1. Errors out.