4c881027a1
- persistent files - Hiscore
39 lines
934 B
GDScript
39 lines
934 B
GDScript
extends Node
|
|
|
|
|
|
signal levelup
|
|
signal start
|
|
|
|
var maxspeed = 260
|
|
var speed = 100
|
|
var score = 0
|
|
var gamerunning = false
|
|
|
|
var hiscore
|
|
|
|
func _ready() -> void:
|
|
load_save()
|
|
#write_save()
|
|
|
|
func load_save():
|
|
var data : FileAccess
|
|
if (not FileAccess.file_exists("user://save.json")) or FileAccess.open("user://save.json",FileAccess.READ_WRITE).get_as_text() == "":
|
|
data = FileAccess.open("user://save.json",FileAccess.WRITE)
|
|
data.store_string(FileAccess.open("res://code/first_save.json",FileAccess.READ).get_as_text())
|
|
data.close()
|
|
data = FileAccess.open("user://save.json",FileAccess.READ)
|
|
var contenttext = JSON.parse_string(data.get_as_text())
|
|
print(contenttext)
|
|
hiscore = contenttext["hiscore"]
|
|
|
|
|
|
func write_save():
|
|
var data : FileAccess
|
|
data = FileAccess.open("user://save.json",FileAccess.WRITE)
|
|
data.store_string(
|
|
JSON.stringify(
|
|
{
|
|
"hiscore":$"/root/Game/Gui/HiscoreContainer/hiscore".get_score()
|
|
}
|
|
)
|
|
)
|