+1 vote

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!

in Projects by (63 points)

1 Answer

+1 vote

You can create JSON and save it to disk like this

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()

Here is an example about saving progress in JSON.
https://docs.godotengine.org/en/3.1/tutorials/io/saving_games.html

by (16 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.

Categories