freettrpg/scripts/createStats.gd
Patrick_Pluto e5911fd155 Version: 0.0.1
First major release, refined the creator, added stats to the main game, added a menu to view stats.
2024-06-15 20:33:37 +02:00

27 lines
641 B
GDScript

extends Node
func saveJSON():
var save_path = str("user://player_data"+$input_id.text+".json")
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 _on_button_pressed():
saveJSON()
func _process(delta):
if Input.is_action_pressed("escape"):
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")