forked from interstellar_development/freettrpg
e5911fd155
First major release, refined the creator, added stats to the main game, added a menu to view stats.
27 lines
641 B
GDScript
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")
|