class_callable.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Callable.xml.
  6. .. _class_Callable:
  7. Callable
  8. ========
  9. A built-in type representing a method or a standalone function.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. **Callable** is a built-in :ref:`Variant<class_Variant>` type that represents a function. It can either be a method within an :ref:`Object<class_Object>` instance, or a custom callable used for different purposes (see :ref:`is_custom<class_Callable_method_is_custom>`). Like all :ref:`Variant<class_Variant>` types, it can be stored in variables and passed to other functions. It is most commonly used for signal callbacks.
  14. .. tabs::
  15. .. code-tab:: gdscript
  16. func print_args(arg1, arg2, arg3 = ""):
  17. prints(arg1, arg2, arg3)
  18. func test():
  19. var callable = Callable(self, "print_args")
  20. callable.call("hello", "world") # Prints "hello world ".
  21. callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(node.gd)::print_args".
  22. callable.call("invalid") # Invalid call, should have at least 2 arguments.
  23. .. code-tab:: csharp
  24. // Default parameter values are not supported.
  25. public void PrintArgs(Variant arg1, Variant arg2, Variant arg3 = default)
  26. {
  27. GD.PrintS(arg1, arg2, arg3);
  28. }
  29. public void Test()
  30. {
  31. // Invalid calls fail silently.
  32. Callable callable = new Callable(this, MethodName.PrintArgs);
  33. callable.Call("hello", "world"); // Default parameter values are not supported, should have 3 arguments.
  34. callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs".
  35. callable.Call("invalid"); // Invalid call, should have 3 arguments.
  36. }
  37. In GDScript, it's possible to create lambda functions within a method. Lambda functions are custom callables that are not associated with an :ref:`Object<class_Object>` instance. Optionally, lambda functions can also be named. The name will be displayed in the debugger, or when calling :ref:`get_method<class_Callable_method_get_method>`.
  38. ::
  39. func _init():
  40. var my_lambda = func (message):
  41. print(message)
  42. # Prints Hello everyone!
  43. my_lambda.call("Hello everyone!")
  44. # Prints "Attack!", when the button_pressed signal is emitted.
  45. button_pressed.connect(func(): print("Attack!"))
  46. In GDScript, you can access methods and global functions as **Callable**\ s:
  47. ::
  48. tween.tween_callback(node.queue_free) # Object methods.
  49. tween.tween_callback(array.clear) # Methods of built-in types.
  50. tween.tween_callback(print.bind("Test")) # Global functions.
  51. \ **Note:** :ref:`Dictionary<class_Dictionary>` does not support the above due to ambiguity with keys.
  52. ::
  53. var dictionary = {"hello": "world"}
  54. # This will not work, `clear` is treated as a key.
  55. tween.tween_callback(dictionary.clear)
  56. # This will work.
  57. tween.tween_callback(Callable.create(dictionary, "clear"))
  58. .. note::
  59. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  60. .. rst-class:: classref-reftable-group
  61. Constructors
  62. ------------
  63. .. table::
  64. :widths: auto
  65. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>`\ (\ ) |
  67. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>`\ (\ from\: :ref:`Callable<class_Callable>`\ ) |
  69. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>`\ (\ object\: :ref:`Object<class_Object>`, method\: :ref:`StringName<class_StringName>`\ ) |
  71. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  72. .. rst-class:: classref-reftable-group
  73. Methods
  74. -------
  75. .. table::
  76. :widths: auto
  77. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Callable<class_Callable>` | :ref:`bind<class_Callable_method_bind>`\ (\ ...\ ) |vararg| |const| |
  79. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Callable<class_Callable>` | :ref:`bindv<class_Callable_method_bindv>`\ (\ arguments\: :ref:`Array<class_Array>`\ ) |
  81. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Variant<class_Variant>` | :ref:`call<class_Callable_method_call>`\ (\ ...\ ) |vararg| |const| |
  83. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | |void| | :ref:`call_deferred<class_Callable_method_call_deferred>`\ (\ ...\ ) |vararg| |const| |
  85. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Variant<class_Variant>` | :ref:`callv<class_Callable_method_callv>`\ (\ arguments\: :ref:`Array<class_Array>`\ ) |const| |
  87. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Callable<class_Callable>` | :ref:`create<class_Callable_method_create>`\ (\ variant\: :ref:`Variant<class_Variant>`, method\: :ref:`StringName<class_StringName>`\ ) |static| |
  89. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`int<class_int>` | :ref:`get_argument_count<class_Callable_method_get_argument_count>`\ (\ ) |const| |
  91. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Array<class_Array>` | :ref:`get_bound_arguments<class_Callable_method_get_bound_arguments>`\ (\ ) |const| |
  93. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`int<class_int>` | :ref:`get_bound_arguments_count<class_Callable_method_get_bound_arguments_count>`\ (\ ) |const| |
  95. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`StringName<class_StringName>` | :ref:`get_method<class_Callable_method_get_method>`\ (\ ) |const| |
  97. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Object<class_Object>` | :ref:`get_object<class_Callable_method_get_object>`\ (\ ) |const| |
  99. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`int<class_int>` | :ref:`get_object_id<class_Callable_method_get_object_id>`\ (\ ) |const| |
  101. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`int<class_int>` | :ref:`get_unbound_arguments_count<class_Callable_method_get_unbound_arguments_count>`\ (\ ) |const| |
  103. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`int<class_int>` | :ref:`hash<class_Callable_method_hash>`\ (\ ) |const| |
  105. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`bool<class_bool>` | :ref:`is_custom<class_Callable_method_is_custom>`\ (\ ) |const| |
  107. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`is_null<class_Callable_method_is_null>`\ (\ ) |const| |
  109. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`bool<class_bool>` | :ref:`is_standard<class_Callable_method_is_standard>`\ (\ ) |const| |
  111. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`bool<class_bool>` | :ref:`is_valid<class_Callable_method_is_valid>`\ (\ ) |const| |
  113. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | |void| | :ref:`rpc<class_Callable_method_rpc>`\ (\ ...\ ) |vararg| |const| |
  115. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | |void| | :ref:`rpc_id<class_Callable_method_rpc_id>`\ (\ peer_id\: :ref:`int<class_int>`, ...\ ) |vararg| |const| |
  117. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Callable<class_Callable>` | :ref:`unbind<class_Callable_method_unbind>`\ (\ argcount\: :ref:`int<class_int>`\ ) |const| |
  119. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  120. .. rst-class:: classref-reftable-group
  121. Operators
  122. ---------
  123. .. table::
  124. :widths: auto
  125. +-------------------------+---------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Callable_operator_neq_Callable>`\ (\ right\: :ref:`Callable<class_Callable>`\ ) |
  127. +-------------------------+---------------------------------------------------------------------------------------------------------+
  128. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Callable_operator_eq_Callable>`\ (\ right\: :ref:`Callable<class_Callable>`\ ) |
  129. +-------------------------+---------------------------------------------------------------------------------------------------------+
  130. .. rst-class:: classref-section-separator
  131. ----
  132. .. rst-class:: classref-descriptions-group
  133. Constructor Descriptions
  134. ------------------------
  135. .. _class_Callable_constructor_Callable:
  136. .. rst-class:: classref-constructor
  137. :ref:`Callable<class_Callable>` **Callable**\ (\ ) :ref:`🔗<class_Callable_constructor_Callable>`
  138. Constructs an empty **Callable**, with no object nor method bound.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. rst-class:: classref-constructor
  142. :ref:`Callable<class_Callable>` **Callable**\ (\ from\: :ref:`Callable<class_Callable>`\ )
  143. Constructs a **Callable** as a copy of the given **Callable**.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. rst-class:: classref-constructor
  147. :ref:`Callable<class_Callable>` **Callable**\ (\ object\: :ref:`Object<class_Object>`, method\: :ref:`StringName<class_StringName>`\ )
  148. Creates a new **Callable** for the method named ``method`` in the specified ``object``.
  149. \ **Note:** For methods of built-in :ref:`Variant<class_Variant>` types, use :ref:`create<class_Callable_method_create>` instead.
  150. .. rst-class:: classref-section-separator
  151. ----
  152. .. rst-class:: classref-descriptions-group
  153. Method Descriptions
  154. -------------------
  155. .. _class_Callable_method_bind:
  156. .. rst-class:: classref-method
  157. :ref:`Callable<class_Callable>` **bind**\ (\ ...\ ) |vararg| |const| :ref:`🔗<class_Callable_method_bind>`
  158. Returns a copy of this **Callable** with one or more arguments bound. When called, the bound arguments are passed *after* the arguments supplied by :ref:`call<class_Callable_method_call>`. See also :ref:`unbind<class_Callable_method_unbind>`.
  159. \ **Note:** When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_Callable_method_bindv:
  163. .. rst-class:: classref-method
  164. :ref:`Callable<class_Callable>` **bindv**\ (\ arguments\: :ref:`Array<class_Array>`\ ) :ref:`🔗<class_Callable_method_bindv>`
  165. Returns a copy of this **Callable** with one or more arguments bound, reading them from an array. When called, the bound arguments are passed *after* the arguments supplied by :ref:`call<class_Callable_method_call>`. See also :ref:`unbind<class_Callable_method_unbind>`.
  166. \ **Note:** When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_Callable_method_call:
  170. .. rst-class:: classref-method
  171. :ref:`Variant<class_Variant>` **call**\ (\ ...\ ) |vararg| |const| :ref:`🔗<class_Callable_method_call>`
  172. Calls the method represented by this **Callable**. Arguments can be passed and should match the method's signature.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_Callable_method_call_deferred:
  176. .. rst-class:: classref-method
  177. |void| **call_deferred**\ (\ ...\ ) |vararg| |const| :ref:`🔗<class_Callable_method_call_deferred>`
  178. Calls the method represented by this **Callable** in deferred mode, i.e. at the end of the current frame. Arguments can be passed and should match the method's signature.
  179. .. tabs::
  180. .. code-tab:: gdscript
  181. func _ready():
  182. grab_focus.call_deferred()
  183. .. code-tab:: csharp
  184. public override void _Ready()
  185. {
  186. Callable.From(GrabFocus).CallDeferred();
  187. }
  188. \ **Note:** Deferred calls are processed at idle time. Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they'll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
  189. See also :ref:`Object.call_deferred<class_Object_method_call_deferred>`.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_Callable_method_callv:
  193. .. rst-class:: classref-method
  194. :ref:`Variant<class_Variant>` **callv**\ (\ arguments\: :ref:`Array<class_Array>`\ ) |const| :ref:`🔗<class_Callable_method_callv>`
  195. Calls the method represented by this **Callable**. Unlike :ref:`call<class_Callable_method_call>`, this method expects all arguments to be contained inside the ``arguments`` :ref:`Array<class_Array>`.
  196. .. rst-class:: classref-item-separator
  197. ----
  198. .. _class_Callable_method_create:
  199. .. rst-class:: classref-method
  200. :ref:`Callable<class_Callable>` **create**\ (\ variant\: :ref:`Variant<class_Variant>`, method\: :ref:`StringName<class_StringName>`\ ) |static| :ref:`🔗<class_Callable_method_create>`
  201. Creates a new **Callable** for the method named ``method`` in the specified ``variant``. To represent a method of a built-in :ref:`Variant<class_Variant>` type, a custom callable is used (see :ref:`is_custom<class_Callable_method_is_custom>`). If ``variant`` is :ref:`Object<class_Object>`, then a standard callable will be created instead.
  202. \ **Note:** This method is always necessary for the :ref:`Dictionary<class_Dictionary>` type, as property syntax is used to access its entries. You may also use this method when ``variant``'s type is not known in advance (for polymorphism).
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_Callable_method_get_argument_count:
  206. .. rst-class:: classref-method
  207. :ref:`int<class_int>` **get_argument_count**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_argument_count>`
  208. Returns the total number of arguments this **Callable** should take, including optional arguments. This means that any arguments bound with :ref:`bind<class_Callable_method_bind>` are *subtracted* from the result, and any arguments unbound with :ref:`unbind<class_Callable_method_unbind>` are *added* to the result.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_Callable_method_get_bound_arguments:
  212. .. rst-class:: classref-method
  213. :ref:`Array<class_Array>` **get_bound_arguments**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_bound_arguments>`
  214. Returns the array of arguments bound via successive :ref:`bind<class_Callable_method_bind>` or :ref:`unbind<class_Callable_method_unbind>` calls. These arguments will be added *after* the arguments passed to the call, from which :ref:`get_unbound_arguments_count<class_Callable_method_get_unbound_arguments_count>` arguments on the right have been previously excluded.
  215. ::
  216. func get_effective_arguments(callable, call_args):
  217. assert(call_args.size() - callable.get_unbound_arguments_count() >= 0)
  218. var result = call_args.slice(0, call_args.size() - callable.get_unbound_arguments_count())
  219. result.append_array(callable.get_bound_arguments())
  220. return result
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_Callable_method_get_bound_arguments_count:
  224. .. rst-class:: classref-method
  225. :ref:`int<class_int>` **get_bound_arguments_count**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_bound_arguments_count>`
  226. Returns the total amount of arguments bound via successive :ref:`bind<class_Callable_method_bind>` or :ref:`unbind<class_Callable_method_unbind>` calls. This is the same as the size of the array returned by :ref:`get_bound_arguments<class_Callable_method_get_bound_arguments>`. See :ref:`get_bound_arguments<class_Callable_method_get_bound_arguments>` for details.
  227. \ **Note:** The :ref:`get_bound_arguments_count<class_Callable_method_get_bound_arguments_count>` and :ref:`get_unbound_arguments_count<class_Callable_method_get_unbound_arguments_count>` methods can both return positive values.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_Callable_method_get_method:
  231. .. rst-class:: classref-method
  232. :ref:`StringName<class_StringName>` **get_method**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_method>`
  233. Returns the name of the method represented by this **Callable**. If the callable is a GDScript lambda function, returns the function's name or ``"<anonymous lambda>"``.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_Callable_method_get_object:
  237. .. rst-class:: classref-method
  238. :ref:`Object<class_Object>` **get_object**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_object>`
  239. Returns the object on which this **Callable** is called.
  240. .. rst-class:: classref-item-separator
  241. ----
  242. .. _class_Callable_method_get_object_id:
  243. .. rst-class:: classref-method
  244. :ref:`int<class_int>` **get_object_id**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_object_id>`
  245. Returns the ID of this **Callable**'s object (see :ref:`Object.get_instance_id<class_Object_method_get_instance_id>`).
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_Callable_method_get_unbound_arguments_count:
  249. .. rst-class:: classref-method
  250. :ref:`int<class_int>` **get_unbound_arguments_count**\ (\ ) |const| :ref:`🔗<class_Callable_method_get_unbound_arguments_count>`
  251. Returns the total amount of arguments unbound via successive :ref:`bind<class_Callable_method_bind>` or :ref:`unbind<class_Callable_method_unbind>` calls. See :ref:`get_bound_arguments<class_Callable_method_get_bound_arguments>` for details.
  252. \ **Note:** The :ref:`get_bound_arguments_count<class_Callable_method_get_bound_arguments_count>` and :ref:`get_unbound_arguments_count<class_Callable_method_get_unbound_arguments_count>` methods can both return positive values.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_Callable_method_hash:
  256. .. rst-class:: classref-method
  257. :ref:`int<class_int>` **hash**\ (\ ) |const| :ref:`🔗<class_Callable_method_hash>`
  258. Returns the 32-bit hash value of this **Callable**'s object.
  259. \ **Note:** **Callable**\ s with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does *not* imply the callables are equal, because different callables can have identical hash values due to hash collisions. The engine uses a 32-bit hash algorithm for :ref:`hash<class_Callable_method_hash>`.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_Callable_method_is_custom:
  263. .. rst-class:: classref-method
  264. :ref:`bool<class_bool>` **is_custom**\ (\ ) |const| :ref:`🔗<class_Callable_method_is_custom>`
  265. Returns ``true`` if this **Callable** is a custom callable. Custom callables are used:
  266. - for binding/unbinding arguments (see :ref:`bind<class_Callable_method_bind>` and :ref:`unbind<class_Callable_method_unbind>`);
  267. - for representing methods of built-in :ref:`Variant<class_Variant>` types (see :ref:`create<class_Callable_method_create>`);
  268. - for representing global, lambda, and RPC functions in GDScript;
  269. - for other purposes in the core, GDExtension, and C#.
  270. .. rst-class:: classref-item-separator
  271. ----
  272. .. _class_Callable_method_is_null:
  273. .. rst-class:: classref-method
  274. :ref:`bool<class_bool>` **is_null**\ (\ ) |const| :ref:`🔗<class_Callable_method_is_null>`
  275. Returns ``true`` if this **Callable** has no target to call the method on. Equivalent to ``callable == Callable()``.
  276. \ **Note:** This is *not* the same as ``not is_valid()`` and using ``not is_null()`` will *not* guarantee that this callable can be called. Use :ref:`is_valid<class_Callable_method_is_valid>` instead.
  277. .. rst-class:: classref-item-separator
  278. ----
  279. .. _class_Callable_method_is_standard:
  280. .. rst-class:: classref-method
  281. :ref:`bool<class_bool>` **is_standard**\ (\ ) |const| :ref:`🔗<class_Callable_method_is_standard>`
  282. Returns ``true`` if this **Callable** is a standard callable. This method is the opposite of :ref:`is_custom<class_Callable_method_is_custom>`. Returns ``false`` if this callable is a lambda function.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_Callable_method_is_valid:
  286. .. rst-class:: classref-method
  287. :ref:`bool<class_bool>` **is_valid**\ (\ ) |const| :ref:`🔗<class_Callable_method_is_valid>`
  288. Returns ``true`` if the callable's object exists and has a valid method name assigned, or is a custom callable.
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_Callable_method_rpc:
  292. .. rst-class:: classref-method
  293. |void| **rpc**\ (\ ...\ ) |vararg| |const| :ref:`🔗<class_Callable_method_rpc>`
  294. Perform an RPC (Remote Procedure Call) on all connected peers. This is used for multiplayer and is normally not available, unless the function being called has been marked as *RPC* (using :ref:`@GDScript.@rpc<class_@GDScript_annotation_@rpc>` or :ref:`Node.rpc_config<class_Node_method_rpc_config>`). Calling this method on unsupported functions will result in an error. See :ref:`Node.rpc<class_Node_method_rpc>`.
  295. .. rst-class:: classref-item-separator
  296. ----
  297. .. _class_Callable_method_rpc_id:
  298. .. rst-class:: classref-method
  299. |void| **rpc_id**\ (\ peer_id\: :ref:`int<class_int>`, ...\ ) |vararg| |const| :ref:`🔗<class_Callable_method_rpc_id>`
  300. Perform an RPC (Remote Procedure Call) on a specific peer ID (see multiplayer documentation for reference). This is used for multiplayer and is normally not available unless the function being called has been marked as *RPC* (using :ref:`@GDScript.@rpc<class_@GDScript_annotation_@rpc>` or :ref:`Node.rpc_config<class_Node_method_rpc_config>`). Calling this method on unsupported functions will result in an error. See :ref:`Node.rpc_id<class_Node_method_rpc_id>`.
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_Callable_method_unbind:
  304. .. rst-class:: classref-method
  305. :ref:`Callable<class_Callable>` **unbind**\ (\ argcount\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_Callable_method_unbind>`
  306. Returns a copy of this **Callable** with a number of arguments unbound. In other words, when the new callable is called the last few arguments supplied by the user are ignored, according to ``argcount``. The remaining arguments are passed to the callable. This allows to use the original callable in a context that attempts to pass more arguments than this callable can handle, e.g. a signal with a fixed number of arguments. See also :ref:`bind<class_Callable_method_bind>`.
  307. \ **Note:** When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
  308. ::
  309. func _ready():
  310. foo.unbind(1).call(1, 2) # Calls foo(1).
  311. foo.bind(3, 4).unbind(1).call(1, 2) # Calls foo(1, 3, 4), note that it does not change the arguments from bind.
  312. .. rst-class:: classref-section-separator
  313. ----
  314. .. rst-class:: classref-descriptions-group
  315. Operator Descriptions
  316. ---------------------
  317. .. _class_Callable_operator_neq_Callable:
  318. .. rst-class:: classref-operator
  319. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_Callable_operator_neq_Callable>`
  320. Returns ``true`` if both **Callable**\ s invoke different targets.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_Callable_operator_eq_Callable:
  324. .. rst-class:: classref-operator
  325. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_Callable_operator_eq_Callable>`
  326. Returns ``true`` if both **Callable**\ s invoke the same custom target.
  327. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  328. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  329. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  330. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  331. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  332. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  333. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  334. .. |void| replace:: :abbr:`void (No return value.)`