2020-02-22 14:59:09 +01:00
<?xml version="1.0" encoding="UTF-8" ?>
2022-02-14 14:18:53 +01:00
<class name= "Signal" version= "4.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2020-02-22 14:59:09 +01:00
<brief_description >
2022-11-05 18:07:53 +01:00
Built-in type representing a signal defined in an object.
2020-02-22 14:59:09 +01:00
</brief_description>
<description >
2022-11-05 18:07:53 +01:00
[Signal] is a built-in [Variant] type that represents a signal of an [Object] instance. Like all [Variant] types, it can be stored in variables and passed to functions. Signals allow all connected [Callable]s (and by extension their respective objects) to listen and react to events, without directly referencing one another. This keeps the code flexible and easier to manage.
In GDScript, signals can be declared with the [code]signal[/code] keyword. In C#, you may use the [code][Signal][/code] attribute on a delegate.
[codeblock]
[gdscript]
signal attacked
# Additional arguments may be declared.
# These arguments must be passed when the signal is emitted.
signal item_dropped(item_name, amount)
[/gdscript]
[csharp]
[Signal]
delegate void Attacked();
// Additional arguments may be declared.
// These arguments must be passed when the signal is emitted.
[Signal]
delegate void ItemDropped(itemName: string, amount: int);
[/csharp]
[/codeblock]
2020-02-22 14:59:09 +01:00
</description>
<tutorials >
2022-04-08 16:25:45 +02:00
<link title= "Using Signals" > $DOCS_URL/getting_started/step_by_step/signals.html</link>
<link title= "GDScript Basics" > $DOCS_URL/tutorials/scripting/gdscript/gdscript_basics.html#signals</link>
2020-02-22 14:59:09 +01:00
</tutorials>
2021-09-21 04:49:02 +02:00
<constructors >
<constructor name= "Signal" >
2021-07-30 15:28:05 +02:00
<return type= "Signal" />
2020-11-09 17:46:03 +01:00
<description >
2022-11-05 18:07:53 +01:00
Constructs an empty [Signal] with no object nor signal name bound.
2020-11-09 17:46:03 +01:00
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Signal" >
2021-07-30 15:28:05 +02:00
<return type= "Signal" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "from" type= "Signal" />
2020-11-09 17:46:03 +01:00
<description >
Constructs a [Signal] as a copy of the given [Signal].
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Signal" >
2021-07-30 15:28:05 +02:00
<return type= "Signal" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "object" type= "Object" />
<param index= "1" name= "signal" type= "StringName" />
2020-02-22 14:59:09 +01:00
<description >
2022-11-05 18:07:53 +01:00
Creates a new [Signal] named [param signal] in the specified [param object].
2020-02-22 14:59:09 +01:00
</description>
2021-09-21 04:49:02 +02:00
</constructor>
</constructors>
<methods >
2020-02-22 14:59:09 +01:00
<method name= "connect" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "callable" type= "Callable" />
<param index= "1" name= "flags" type= "int" default= "0" />
2020-02-22 14:59:09 +01:00
<description >
2022-11-05 18:07:53 +01:00
Connects this signal to the specified [param callable]. Optional [param flags] can be also added to configure the connection's behavior (see [enum Object.ConnectFlags] constants). You can provide additional arguments to the connected [param callable] by using [method Callable.bind].
A signal can only be connected once to the same [Callable]. If the signal is already connected, returns [constant ERR_INVALID_PARAMETER] and pushes an error message, unless the signal is connected with [constant Object.CONNECT_REFERENCE_COUNTED]. To prevent this, use [method is_connected] first to check for existing connections.
2021-09-19 18:55:23 +02:00
[codeblock]
for button in $Buttons.get_children():
2022-11-05 18:07:53 +01:00
button.pressed.connect(_on_pressed.bind(button))
2021-09-19 18:55:23 +02:00
2022-11-05 18:07:53 +01:00
func _on_pressed(button):
2021-09-19 18:55:23 +02:00
print(button.name, " was pressed")
[/codeblock]
2020-02-22 14:59:09 +01:00
</description>
</method>
<method name= "disconnect" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "callable" type= "Callable" />
2020-02-22 14:59:09 +01:00
<description >
2022-11-05 18:07:53 +01:00
Disconnects this signal from the specified [Callable]. If the connection does not exist, generates an error. Use [method is_connected] to make sure that the connection exists.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "emit" qualifiers= "vararg const" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2020-02-22 14:59:09 +01:00
<description >
2022-11-05 18:07:53 +01:00
Emits this signal. All [Callable]s connected to this signal will be triggered. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "get_connections" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
2020-02-22 14:59:09 +01:00
<description >
2020-03-03 19:21:21 +01:00
Returns the list of [Callable]s connected to this signal.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "get_name" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "StringName" />
2020-02-22 14:59:09 +01:00
<description >
2020-03-03 19:21:21 +01:00
Returns the name of this signal.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "get_object" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Object" />
2020-02-22 14:59:09 +01:00
<description >
2020-03-03 19:21:21 +01:00
Returns the object emitting this signal.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "get_object_id" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2020-02-22 14:59:09 +01:00
<description >
2020-03-03 19:21:21 +01:00
Returns the ID of the object emitting this signal (see [method Object.get_instance_id]).
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "is_connected" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "callable" type= "Callable" />
2020-02-22 14:59:09 +01:00
<description >
2020-03-03 19:21:21 +01:00
Returns [code]true[/code] if the specified [Callable] is connected to this signal.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "is_null" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2020-02-22 14:59:09 +01:00
<description >
2022-11-05 18:07:53 +01:00
Returns [code]true[/code] if the signal's name does not exist in its object, or the object is not valid.
2020-02-22 14:59:09 +01:00
</description>
</method>
2021-09-21 04:49:02 +02:00
</methods>
<operators >
<operator name= "operator !=" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "right" type= "Signal" />
2020-11-10 14:16:20 +01:00
<description >
2022-11-05 18:07:53 +01:00
Returns [code]true[/code] if the signals do not share the same object and name.
2020-11-10 14:16:20 +01:00
</description>
2021-09-21 04:49:02 +02:00
</operator>
<operator name= "operator ==" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "right" type= "Signal" />
2020-11-10 14:16:20 +01:00
<description >
2022-11-05 18:07:53 +01:00
Returns [code]true[/code] if both signals share the same object and name.
2020-11-10 14:16:20 +01:00
</description>
2021-09-21 04:49:02 +02:00
</operator>
</operators>
2020-02-22 14:59:09 +01:00
</class>