Topic was automatically imported from the old Question2Answer platform.
Asked By
Anastasia
Ok so ive been strugling with this for over a month. I need to make c checkpoint that not only saves your stats, but also let you restore your progres when u close the game and come back. You would have a player (Kinematig body) And a save point (Probably area2d)
I am also VERY new to Json and have no idea how exactly it works… I dont even now how to create a JSON, and what to put in it…
PLEASE help!
func Save():
#create new file and open it for writing
var file = File.new()
file.open("res://data.json",file.WRITE)
#sample data
var data = {"health":100,"mana":40}
#convert data to json and store it in the file
file.store_line(to_json(data))
#after the operation is done close the file
file.close()
Then you can load it like this
func Load():
#create new file and open it for reading
var file = File.new()
file.open("res://data.json",file.READ)
#load data from the file and convert it to json
var json_data = parse_json(file.get_as_text())
#print loaded json data
print(json_data)
# you can also access individual values by using . operator
# for example: json_data.health
#after the operation is done close the file
file.close()