Godot Version
Godot 4.2
Question
How do I fix a timer breaking whenever I load a scene?
I use timers on the title screen of my game for various purposes (allowing time for a confirmation sound to play, and showing an error message), and they work exactly as I expect when I directly load into the title screen scene of my game. However, as soon as I return to the title screen, the timers break, and none of the options work as I expect. I’ve tried both creating the timers in code and using nodes and the same exact thing happens. I’ll attach the code for my title screen if anybody can provide help or a better solution.
Note: The uiOption variable is leftover from me using nodes and a single timeout function.
extends Node3D
var uiOption = 0
func _ready():
$interface/ExtrasErr.hide()
if Global.version == 3 or Global.version == 4:
pass
else:
$music.play()
func _process(delta):
pass
func _on_play_pressed():
$uiYes.play()
uiOption = 1
await get_tree().create_timer(0.5).timeout
get_tree().change_scene_to_file("res://scenes/testing_stage.tscn")
func _on_quit_pressed():
$uiYes.play()
uiOption = 2
await get_tree().create_timer(0.5).timeout
get_tree().quit()
func _on_extras_pressed():
$uiYes.play()
if Global.gemsCollected == 11:
uiOption = 3
await get_tree().create_timer(0.5).timeout
else:
$interface/ExtrasErr.show()
await get_tree().create_timer(5).timeout
$interface/ExtrasErr.hide()
func _on_options_pressed():
$uiYes.play()