Minor Changes
This commit is contained in:
parent
01cd337c66
commit
4224f4f755
14 changed files with 278 additions and 0 deletions
38
scripts/createStats.gd
Normal file
38
scripts/createStats.gd
Normal file
|
@ -0,0 +1,38 @@
|
|||
extends Node
|
||||
|
||||
var save_path = "user://player_data.json"
|
||||
|
||||
func saveJSON():
|
||||
var data := {
|
||||
"name": "test",
|
||||
}
|
||||
|
||||
var json_string = JSON.stringify(data)
|
||||
|
||||
var file_access = FileAccess.open(save_path, FileAccess.WRITE)
|
||||
if not file_access:
|
||||
print("An error happened while saving data: ", FileAccess.get_open_error())
|
||||
return
|
||||
|
||||
file_access.store_line(json_string)
|
||||
file_access.close()
|
||||
|
||||
func loadJSON():
|
||||
if not FileAccess.file_exists(save_path):
|
||||
return
|
||||
var file_access = FileAccess.open(save_path, FileAccess.READ)
|
||||
var json_string = file_access.get_line()
|
||||
file_access.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var error = json.parse(json_string)
|
||||
if error:
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||
return
|
||||
|
||||
var data:Dictionary = json.data
|
||||
var test = data.get("name")
|
||||
|
||||
func _on_pressed():
|
||||
saveJSON()
|
||||
loadJSON()
|
Loading…
Add table
Add a link
Reference in a new issue