When I save using the following code, the resulting file has a load of unrecognised characters at the beginning, then on opening won't parse it. Any ideas please?
func _ready():
data = load_save(fn)
if data == null:
print("Failed to load save")
data = data_default
save_save(fn, data)
func load_save(fn): # -> Dictionary:
var f := File.new()
var err = f.open(fn, File.READ) # "res://save.json"
if err != OK:
print("oops")
f.close()
return null
var result := JSON.parse(f.get_as_text())
f.close()
if result.error:
print("Failed to parse save file: ", result.error_string)
return null
return result.result as Dictionary
# SAVE DICTIONARY TO JSON
func save_save(var fn : String, var d):
var file = File.new()
var err = file.open(fn, File.WRITE)
if err != OK:
print("oops saving")
file.store_var(to_json(d), true)
#file.store_var(to_json(d), false)
file.close()
return true
The file:
@\00\00\00\00\00\008\00\00\00{"levels":{"0":{"open":1,"score":0,"stars":0,"time":0}}}
Thanks