From 840e3470498fa03baa70fa35ca22d8031319505b Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Mon, 28 Jul 2025 16:07:35 -0400 Subject: [PATCH] week 5 instructional update --- week5/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/week5/README.md b/week5/README.md index b03814c..1cf5d09 100644 --- a/week5/README.md +++ b/week5/README.md @@ -35,6 +35,27 @@ It is possible that an autoload script can get quite cluttered with information, Now that the game controller is persistent, it does not reload when the level timer completes. As a result, the level loads over and over again because it thinks the time has run out. +### Timer Example + +``` +var timer = Timer.new() +var timeLimit = 10 +var level="res://scenes/game.tscn" + +func _ready() -> void: + add_child(timer) + timer.wait_time = 1 + timer.one_shot = false + timer.connect("timeout", secondCounter) + timer.start() + +func secondCounter() -> void: + timeLimit -=1 + if timeLimit <=0: + print("You lose") + get_tree().call_deferred("change_scene_to_file", level) +``` + We can use this example to show the relationship of the scene manager to the game controller - because the scene manager DOES reload each time the level is updated. As it loads, it will tell the game controller to reset the timer. In `Gamecontroller`: