Skip to content

Commit af6ab3d

Browse files
authored
Merge pull request #10098 from TheSecondReal0/csharp-signal-parameters
Add C# documentation for connecting to GDScript signals with parameters
2 parents d0d797c + a4c0b37 commit af6ab3d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tutorials/scripting/cross_language_scripting.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The following two scripts will be used as references throughout this page.
1919
var my_field: String = "foo"
2020

2121
signal my_signal
22+
signal my_signal_with_params(msg: String, n: int)
2223

2324
func print_node_name(node: Node) -> void:
2425
print(node.get_name())
@@ -34,6 +35,9 @@ The following two scripts will be used as references throughout this page.
3435
func my_signal_handler():
3536
print("The signal handler was called!")
3637

38+
func my_signal_with_params_handler(msg: String, n: int):
39+
print_n_times(msg, n)
40+
3741
.. code-tab:: csharp
3842

3943
using Godot;
@@ -43,6 +47,7 @@ The following two scripts will be used as references throughout this page.
4347
public string myField = "bar";
4448

4549
[Signal] public delegate void MySignalEventHandler();
50+
[Signal] public delegate void MySignalWithParamsEventHandler(string msg, int n);
4651

4752
public void PrintNodeName(Node node)
4853
{
@@ -69,6 +74,11 @@ The following two scripts will be used as references throughout this page.
6974
{
7075
GD.Print("The signal handler was called!");
7176
}
77+
78+
public void MySignalWithParamsHandler(string msg, int n)
79+
{
80+
PrintNTimes(msg, n);
81+
}
7282
}
7383

7484
Instantiating nodes
@@ -213,6 +223,8 @@ defined in GDScript:
213223
214224
my_csharp_node.MySignal.connect(my_signal_handler)
215225
226+
my_csharp_node.MySignalWithParams.connect(my_signal_with_params_handler)
227+
216228
Connecting to GDScript signals from C#
217229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218230

@@ -223,6 +235,8 @@ because no C# static types exist for signals defined by GDScript:
223235
224236
myGDScriptNode.Connect("my_signal", Callable.From(MySignalHandler));
225237
238+
myGDScriptNode.Connect("my_signal_with_params", Callable.From<string, int>(MySignalWithParamsHandler));
239+
226240
Inheritance
227241
-----------
228242

0 commit comments

Comments
 (0)