Merge pull request #78274 from adamscott/add-callable-native-method-note

Add note in `Callable` documentation about methods of native types
This commit is contained in:
Rémi Verschelde 2023-06-16 10:19:56 +02:00
commit 494b29cfb7
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 11 additions and 0 deletions

View File

@ -46,6 +46,17 @@
# Prints "Attack!", when the button_pressed signal is emitted.
button_pressed.connect(func(): print("Attack!"))
[/codeblock]
[b]Note:[/b] Methods of native types such as [Signal], [Array], or [Dictionary] are not of type [Callable] in order to avoid unnecessary overhead. If you need to pass those methods as [Callable], use a lambda function as a wrapper.
[codeblock]
func _init():
var my_dictionary = { "hello": "world" }
# This will not work, `clear` is not a callable.
create_tween().tween_callback(my_dictionary.clear)
# This will work, as lambdas are custom callables.
create_tween().tween_callback(func(): my_dictionary.clear())
[/codeblock]
</description>
<tutorials>
</tutorials>