From 6fb5521f48c4866b3d08112dd03533a7b77bd2f9 Mon Sep 17 00:00:00 2001 From: aaronmsimon <81662612+aaronmsimon@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:41:17 -0700 Subject: [PATCH] P13 Game Over Score and Highscore Video 13 in series https://www.youtube.com/playlist?list=PL9FzW-m48fn09w6j8NowI_pSBVcsb3V78 Was getting errors after restarting after death and couldn't figure it out. I realized thanks to this post: https://github.com/godotengine/godot/issues/71032 that I was not removing the event! Removed it at the scene unloading and it worked! --- Galaxy Defiance/World.cs | 5 ++++ Galaxy Defiance/components/GameStats.cs | 2 ++ Galaxy Defiance/menus/GameOver.cs | 20 +++++++++++++ Galaxy Defiance/menus/game_over.tscn | 38 ++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Galaxy Defiance/World.cs b/Galaxy Defiance/World.cs index ead9b9e..1dc37fc 100644 --- a/Galaxy Defiance/World.cs +++ b/Galaxy Defiance/World.cs @@ -22,6 +22,11 @@ public override void _Ready() }; } + public override void _ExitTree() + { + gameStats.ScoreChanged -= UpdateScoreLabel; + } + private void UpdateScoreLabel(int newScore) { scoreLabel.Text = "Score: " + newScore; diff --git a/Galaxy Defiance/components/GameStats.cs b/Galaxy Defiance/components/GameStats.cs index e0706d3..449fc26 100644 --- a/Galaxy Defiance/components/GameStats.cs +++ b/Galaxy Defiance/components/GameStats.cs @@ -20,4 +20,6 @@ public int Score EmitSignal(SignalName.ScoreChanged, score); } } + + public int HighScore { get; set; } } diff --git a/Galaxy Defiance/menus/GameOver.cs b/Galaxy Defiance/menus/GameOver.cs index 55f57ff..4178936 100644 --- a/Galaxy Defiance/menus/GameOver.cs +++ b/Galaxy Defiance/menus/GameOver.cs @@ -2,10 +2,30 @@ public partial class GameOver : Control { + [Export] private GameStats gameStats; + + private Label scoreValue; + private Label highScoreValue; + + public override void _Ready() + { + scoreValue = GetNode