The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm working on my first save system and it consists of multiple dictionaries. Simply the players character, the enemy, and a dictionary for the icon of each item they have equipped, so anywhere between 2 and 10 depending. However I can't figure out how to parse past the first dictionary. They're all saved on the same JSON file, which looks like this with three dictionaries:


and the code for parsing it looks like this:"res://", File.READ)
while not save_game.eof_reached():
    var current_line = parse_json(save_game.get_as_text())

It works great for everything in the first dictionary, but the UpgradeIcon key and all the keys from the boss are completely ignored. I'm sure I'm just making a beginners mistake but I couldn't seem to find a solution in the documentation.

in Engine by (12 points)
edited by

1 Answer

0 votes

You could just make them into one json:
{ "character" : {"AttackPower":10,"Boss":"res://Bosses/SkeletalArcher.tscn","Character":"res://Characters/PitFighter.tscn","DodgeChance":10,"Energy":100,"HP":110,"Potions":4,"SleepChance":5,"Speed":2,"_AttackPower":10,"_BossHP":80,"_DodgeChance":10,"_Energy":100,"_HP":89,"_Speed":2,"fv":151.5}, "enemy" : {"UpgradeIcon":"res://Upgrades/SandmansBlackjackIcon.tscn"}, "icon" : {"AttackPower":7,"DodgeChance":20,"HP":100,"Speed":1.4,"_DodgeChance":20,"_HP":80} }


[ {"AttackPower":10,"Boss":"res://Bosses/SkeletalArcher.tscn","Character":"res://Characters/PitFighter.tscn","DodgeChance":10,"Energy":100,"HP":110,"Potions":4,"SleepChance":5,"Speed":2,"_AttackPower":10,"_BossHP":80,"_DodgeChance":10,"_Energy":100,"_HP":89,"_Speed":2,"fv":151.5}, {"UpgradeIcon":"res://Upgrades/SandmansBlackjackIcon.tscn"}, {"AttackPower":7,"DodgeChance":20,"HP":100,"Speed":1.4,"_DodgeChance":20,"_HP":80}]

by (114 points)

How would you write the save function to make them save like that?

You need to declare a single array which will contain all your dictionaries, then save that array into a JSON file.

What would be the most elegant way to write that?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.