summaryrefslogtreecommitdiff
path: root/doc/classes/Signal.xml
blob: 3c98a0a0e1b591925c3c35f0adee901448b11427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Signal" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
	<brief_description>
		Class representing a signal defined in an object.
	</brief_description>
	<description>
		Signals can be connected to [Callable]s and emitted. When a signal is emitted, all connected callables are called.
		Usually signals are accessed as properties of objects, but it's also possible to assign them to variables and pass them around, allowing for more dynamic connections.
	</description>
	<tutorials>
		<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>
	</tutorials>
	<constructors>
		<constructor name="Signal">
			<return type="Signal" />
			<description>
				Constructs a null [Signal] with no object nor signal name bound.
			</description>
		</constructor>
		<constructor name="Signal">
			<return type="Signal" />
			<param index="0" name="from" type="Signal" />
			<description>
				Constructs a [Signal] as a copy of the given [Signal].
			</description>
		</constructor>
		<constructor name="Signal">
			<return type="Signal" />
			<param index="0" name="object" type="Object" />
			<param index="1" name="signal" type="StringName" />
			<description>
				Creates a new [Signal] with the name [param signal] in the specified [param object].
			</description>
		</constructor>
	</constructors>
	<methods>
		<method name="connect">
			<return type="int" />
			<param index="0" name="callable" type="Callable" />
			<param index="1" name="flags" type="int" default="0" />
			<description>
				Connects this signal to the specified [Callable], optionally providing connection flags. You can provide additional arguments to the connected method call by using [method Callable.bind].
				[codeblock]
				for button in $Buttons.get_children():
				    button.pressed.connect(on_pressed.bind(button))

				func on_pressed(button):
				    print(button.name, " was pressed")
				[/codeblock]
			</description>
		</method>
		<method name="disconnect">
			<return type="void" />
			<param index="0" name="callable" type="Callable" />
			<description>
				Disconnects this signal from the specified [Callable].
			</description>
		</method>
		<method name="emit" qualifiers="vararg const">
			<return type="void" />
			<description>
				Emits this signal to all connected objects.
			</description>
		</method>
		<method name="get_connections" qualifiers="const">
			<return type="Array" />
			<description>
				Returns the list of [Callable]s connected to this signal.
			</description>
		</method>
		<method name="get_name" qualifiers="const">
			<return type="StringName" />
			<description>
				Returns the name of this signal.
			</description>
		</method>
		<method name="get_object" qualifiers="const">
			<return type="Object" />
			<description>
				Returns the object emitting this signal.
			</description>
		</method>
		<method name="get_object_id" qualifiers="const">
			<return type="int" />
			<description>
				Returns the ID of the object emitting this signal (see [method Object.get_instance_id]).
			</description>
		</method>
		<method name="is_connected" qualifiers="const">
			<return type="bool" />
			<param index="0" name="callable" type="Callable" />
			<description>
				Returns [code]true[/code] if the specified [Callable] is connected to this signal.
			</description>
		</method>
		<method name="is_null" qualifiers="const">
			<return type="bool" />
			<description>
				Returns [code]true[/code] if either object or signal name are not valid.
			</description>
		</method>
	</methods>
	<operators>
		<operator name="operator !=">
			<return type="bool" />
			<param index="0" name="right" type="Signal" />
			<description>
				Returns [code]true[/code] if two signals are not equal.
			</description>
		</operator>
		<operator name="operator ==">
			<return type="bool" />
			<param index="0" name="right" type="Signal" />
			<description>
				Returns [code]true[/code] if two signals are equal, i.e. their object and name are the same.
			</description>
		</operator>
	</operators>
</class>