Found another Godot crime: https://github.com/godotengine/godot/issues/69014
It looks like lambdas do not capture local
variables as they only copy the value of
each variable. However, since Variant
is passed by reference, you can use a
Variant
to get around this problem.
For example, this does not work:
func foobar():
var stop = false
var stop_callback = func():
= true
stop connect(stop_callback)
some_signal.
get_tree().create_timer(10).timeout
await
print(stop) # Always false
But this does:
func foobar():
var stop = { "value": false }
var stop_callback = func():
"value"] = true
stop[connect(stop_callback)
some_signal.
get_tree().create_timer(10).timeout
await
print(stop["value"]) # Either true or false