![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | FT_Anx |
So I’m basically trying to keep adding data into the ‘test.json’ file. The program isn’t ready yet, so I play the scene every time to see if it’s working and adding data. It does add, but then it replaces the content saved every time I restart playing it. How can I solve this?
var infos = []
var title
var description
const SAVE_PATH = "user://test.json"
func save_file_test():
# Load
load_goals()
# Modify
var store_data ={ 'title': title, 'description': description }
# Save
var f = File.new()
f.open(SAVE_PATH, File.WRITE)
if( load_goals() == null ):
infos.append(store_data)
f.store_string(JSON.print(infos, " ", true))
else:
f.seek_end() #Idk if this has any utility here, tbh.
var new_data = load_goals().append(store_data)
f.store_string(JSON.print(new_data, " ", true))
f.close()
func load_goals():
var f = File.new()
f.open(SAVE_PATH, File.READ)
var json = JSON.parse(f.get_as_text())
f.close()
var data = json.result
return data