extends Node var save_path = "user://player_data.json" func saveJSON(): var data := { "name": $input_name.text, "hp": $input_hp.text, "level": $input_level.text } 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 charName = data.get("name") var charHP = data.get("hp") var charLevel = data.get("level") print(charName) print(charHP) print(charLevel) func _on_button_pressed(): saveJSON() loadJSON()