Browse Source

Fix GDExample C++ signal connect example and add explanation (#8381)

* Fix signal connect example, add explanation

* Update tutorials/scripting/gdextension/gdextension_cpp_example.rst

Co-authored-by: David Snopek <[email protected]>

* Update tutorials/scripting/gdextension/gdextension_cpp_example.rst

---------

Co-authored-by: Max Hilbrunner <[email protected]>
Co-authored-by: David Snopek <[email protected]>
Zacrain 1 year ago
parent
commit
5110c2dda8
1 changed files with 13 additions and 2 deletions
  1. 13 2
      tutorials/scripting/gdextension/gdextension_cpp_example.rst

+ 13 - 2
tutorials/scripting/gdextension/gdextension_cpp_example.rst

@@ -596,10 +596,21 @@ This is the required syntax:
 
 
 .. code-block:: cpp
 .. code-block:: cpp
 
 
-    some_other_node->connect("the_signal", this, "my_method");
+    some_other_node->connect("the_signal", Callable(this, "my_method"));
+
+To connect our signal ``the_signal`` from some other node with our method 
+``my_method``, we need to provide the ``connect`` method with the name of the signal 
+and a ``Callable``. The ``Callable`` holds information about an object on which a method 
+can be called. In our case, it associates our current object instance ``this`` with the 
+method ``my_method`` of the object. Then the ``connect`` method will add this to the 
+observers of ``the_signal``. Whenever ``the_signal`` is now emitted, Godot knows which 
+method of which object it needs to call.
 
 
 Note that you can only call ``my_method`` if you've previously registered it in
 Note that you can only call ``my_method`` if you've previously registered it in
-your ``_bind_methods`` method.
+your ``_bind_methods`` method. Otherwise Godot will not know about the existence
+of ``my_method``.
+
+To learn more about ``Callable``, check out the class reference here: :ref:`Callable <class_Callable>`.
 
 
 Having your object sending out signals is more common. For our wobbling
 Having your object sending out signals is more common. For our wobbling
 Godot icon, we'll do something silly just to show how it works. We're going to
 Godot icon, we'll do something silly just to show how it works. We're going to