DuckRun/code/global.gd

40 lines
934 B
GDScript3
Raw Normal View History

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()
}
)
)