jo17off
February 4, 2024, 10:35pm
1
Godot Version
Godot 4.2.1
Question
The first time (in the _ready function) await works without problems and waits for a click, but the second time (in the some_func function) it interrupts the function as return does.
I have a code that looks like this:
signal click
func _ready()
$Button.connect("button_down",button_click)
await click
print("Done 1")
some_func()
print("Done 3")
func some_func():
await click
print("Done 2")
func button_click():
click.emit()
The output will only print:
Done 1
Done 3
But “Done 2” is never printed in the output. I suppose await somehow interrupts the function for some reason, but I don’t know why.
jo17off
February 5, 2024, 12:01am
2
Okay, it’s just asynchronized the callable function and _ready()
I just edited the code like this:
signal click
func _ready()
$Button.connect("button_down",button_click)
await click
print("Done 1")
await some_func()
print("Done 3")
func some_func():
await click
print("Done 2")
func button_click():
click.emit()
And it works! Maybe because my code is more complex, my button in the previous version cannot be pressed.
BTW, you are calling a function that is async so you must await
on the async function call as well.
The compiler is creating “response” handlers, if await
is not present, there is no “handler” to return from the fucntion’s await
.
system
Closed
March 6, 2024, 4:47pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.