hey,
I assume it's simple problem but I'm stuck. In my project I have multiple dictionaries for storing data. The idea was to edit/change those dictionaries during game, then merge them, save in one save file, and on next game start - read saved file, and pass specific keys to multiple dictionaries. And it works fine. But at one point keys are getting duplicated, and dunno where I can fix that. Woudl be grateful for help :)
- with this I merge passed dictionaries and save in one file:
func write_data(url:String, MainDictPlusInv:Dictionary, char1:Dictionary):
MainDictPlusInv["character1"] = char1
file.open(url, File.WRITE)
file.store_line(to_json(MainDictPlusInv))
file.close()
- This is func for calling saving:
func save_data() -> void:
DataTables.write_data(url_PlayerData, {"inventory": inventory}, {"character1": character1})
- and on game startup, I start with loading my saved file (passing whole file in one temp dict - playerData) and then passing it to specific dicts:
inventory = playerData["inventory"]
character1 = playerData["character1"]
The problem is that after loading file me keys the duplicated. And instead of:
"character1":{"hp":6776,"kills":100,"xp":20}
i have:
"character1":{"character1":{"hp":6776,"kills":100,"xp":20}}
after multiple saves - i still have only 1 doubled key. I guess it's something in point 2, where I pass dict with added key but... dunno how to rewrite it to store this in a correct way.