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

in Engine by (171 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

by (108 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.
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 webmaster@godotengine.org with your username.