0 votes

Imagine I have my application's data stored in a json file:

{
    "apples": 5,
    "bananas": 2,
    "kiwis": 0
}

How can I keep my data when I make an update of my game and a variable is added to it ? Like so :

{
    "apples": 5,
    "bananas": 2,
    "kiwis": 0,
    "oranges": 3
}

I'm searching for a clean way to do it

asked Jul 12 in Engine by ZacB (168 points)

1 Answer

+1 vote

You have to overwrite the entire line. Either you already have the full line ready to be written over the old one or you need to read the old data into a variable , make the addition, then write over the old line. There isnt a simple way to traverse the files unfortunately. If you have a lot of data to store its best to make it all organized in one dictionary per file. Dictionaries in dictionaries. ..in dictionaries

answered Jul 13 by happycamper (99 points)
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 How to use this Q&A? before posting your first questions.