Score saving, and loading
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
extends Control
|
||||
|
||||
var save_path = "user://map_scores.save"
|
||||
var map_scores = {}
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
@ -10,3 +12,30 @@ func _on_button_pressed() -> void:
|
||||
func _on_button_map1_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://Game/Maps/map_1.tscn")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
loadData()
|
||||
|
||||
|
||||
func loadData() -> void:
|
||||
if FileAccess.file_exists(save_path):
|
||||
var file = FileAccess.open(save_path, FileAccess.READ)
|
||||
if file:
|
||||
map_scores = file.get_var()
|
||||
file.close()
|
||||
get_node("VBoxContainer/HBoxContainer/first/Label2").text = "Haven't played yet" if map_scores["Map1"] == 0 else "Scored: " + str(map_scores["Map1"]) + " out of 10"
|
||||
print(map_scores)
|
||||
|
||||
else:
|
||||
map_scores["Map1"] = 0
|
||||
|
||||
save_scores()
|
||||
loadData()
|
||||
|
||||
|
||||
func save_scores():
|
||||
var file = FileAccess.open(save_path, FileAccess.WRITE)
|
||||
if file:
|
||||
file.store_var(map_scores)
|
||||
file.close()
|
||||
|
Reference in New Issue
Block a user