Godot Version
3
My highscore works fine but the problem is that it only updates after pressing my retry button
highscoremanager.gd(autoload)
extends Node
var high_score = 0
func _ready():
load_high_score()
func save_high_score(score: int):
if score > high_score:
high_score = score
var file = File.new()
file.open("user://high_score.save", File.WRITE)
file.store_var(high_score)
file.close()
func load_high_score():
var file = File.new()
if file.file_exists("user://high_score.save"):
file.open("user://high_score.save", File.READ)
high_score = file.get_var()
file.close()
else:
high_score = 0
Game.gd
extends Node2D
var score = 0
onready var high_score_label = $HighScoreLabel
onready var score_label = $Timer # Make sure to set the path to your score label node
onready var area = $deatharea
var is_dead = false
func _ready():
var yarn_mouse = $YarnMouse # Adjust the path to your YarnMouse node
yarn_mouse.connect("score_increment", self, "_on_score_increment")
area.connect("death", self, "_on_death")
update_labels()
func _on_score_increment():
if not is_dead:
score += 1
score_label.text = str(score)
print("score is added")
else:
print("not scoring bro")
func _on_death():
is_dead = true
$AnimationPlayer.play("FadeOut")
print("you died")
yield(get_tree().create_timer(0.5), "timeout")
HighScoreManager.save_high_score(score)
$YarnMouse.queue_free()
func _on_Button_pressed():
get_tree().change_scene("res://Scenes/Menu.tscn")
func update_labels():
score_label.text = str(score)
var high_score_label = $HighScoreLabel # Adjust the path to your high score label node
high_score_label.text = "High Score: " + str(HighScoreManager.high_score)
Any ideas???