2024-06-14 09:44:34 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
func saveJSON():
|
2024-06-15 20:33:37 +02:00
|
|
|
var save_path = str("user://player_data"+$input_id.text+".json")
|
|
|
|
|
2024-06-14 09:44:34 +02:00
|
|
|
var data := {
|
2024-06-14 10:34:06 +02:00
|
|
|
"name": $input_name.text,
|
|
|
|
"hp": $input_hp.text,
|
|
|
|
"level": $input_level.text
|
2024-06-14 09:44:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2024-06-14 10:34:06 +02:00
|
|
|
func _on_button_pressed():
|
2024-06-14 09:44:34 +02:00
|
|
|
saveJSON()
|
2024-06-15 20:33:37 +02:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if Input.is_action_pressed("escape"):
|
|
|
|
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|