Godot Version
v4.2.2.stable.official [15073afe3] (Copied straight from Godot)
Question
I don’t know if this issue has been posted before, given it’s simple nature, but a fairly thorough search seems to suggest otherwise. Feel free to let me know if I am incorrect.
It seems like a simple to fix issue, but I’ve been wrestling with it for a couple days now, but to no avail. Like my last post, I’ve been trying to create a custom terminal-like-interface, so naturally, I need a simple API to interface with it. Everything else works perfectly fine, it’s just one final issue that I have with an otherwise pretty forgettable function.
If I want to add a delay between each call to the custom print function, which I know I’ll need at some point, I need a sleep function. I can’t just use
OS.delay_msec()
or,
OS.delay_usec()
because that locks up my entire program, so I need something else, like a timer to act as the delay.
Alas, this leads us to my current problem. For some reason, my implementation doesn’t work, and it seems to be because of the fact that the timer isn’t counting down after explicitly being requested to do so.
My program is setup in a modular fashion, with child scripts being loaded dynamically at runtime and executed, using the aforementioned API that was previously set up for them.
My current implementation uses a timer called “sleepTimer” hooked up as a child of the node that the parent script is linked to. Here is my code:
func sleep(secs: float) -> void:
sleepTimer.wait_time = secs
sleepTimer.start()
await sleepTimer.timeout
The child script then calls it like this:
await parent.sleep(2.0) # or any other delay you want
Trying to print out sleepTimer’s “time_left” parameter always stays what was passed into it (in this example, 2.0), and never counts down. Any idea why this might be happening?