Skip to content

Commit e4cbd48

Browse files
committed
Add await signal args example
1 parent f908cdc commit e4cbd48

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tutorials/scripting/gdscript/gdscript_basics.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,30 @@ This also means that returning a signal from a function that isn't a coroutine w
28662866
With this type safety in place, a function cannot say that it returns an ``int`` while it actually returns a function state object
28672867
during runtime.
28682868

2869+
You can store the arguments passed to the signal's parameters. If there is only one parameter, the awaited value will have the same type as the argument:
2870+
2871+
::
2872+
2873+
func toggled():
2874+
var signal_args = await $Button.toggled
2875+
assert(typeof(signal_args) == TYPE_BOOL)
2876+
2877+
If there is more than one parameter, the awaited value will be of type ``Array``:
2878+
2879+
::
2880+
2881+
func request_completed():
2882+
var signal_args = await $HTTPRequest.request_completed
2883+
assert(typeof(signal_args) == TYPE_ARRAY)
2884+
2885+
Otherwise, the awaited value will be ``null``:
2886+
2887+
::
2888+
2889+
func button_up():
2890+
var signal_args = await $Button.button_up
2891+
assert(signal_args == null)
2892+
28692893
Assert keyword
28702894
--------------
28712895

0 commit comments

Comments
 (0)