summaryrefslogtreecommitdiff
path: root/doc/classes/Object.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/Object.xml')
-rw-r--r--doc/classes/Object.xml26
1 files changed, 20 insertions, 6 deletions
diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml
index 4b77197e29..c8a4b68596 100644
--- a/doc/classes/Object.xml
+++ b/doc/classes/Object.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="Object" category="Core" version="3.2">
+<class name="Object" version="3.2">
<brief_description>
Base class for all non built-in types.
</brief_description>
@@ -9,6 +9,12 @@
Objects do not manage memory. If a class inherits from Object, you will have to delete instances of it manually. To do so, call the [method free] method from your script or delete the instance from C++.
Some classes that extend Object add memory management. This is the case of [Reference], which counts references and deletes itself automatically when no longer referenced. [Node], another fundamental type, deletes all its children when freed from memory.
Objects export properties, which are mainly useful for storage and editing, but not really so much in programming. Properties are exported in [method _get_property_list] and handled in [method _get] and [method _set]. However, scripting languages and C++ have simpler means to export them.
+ Property membership can be tested directly in GDScript using [code]in[/code]:
+ [codeblock]
+ var n = Node2D.new()
+ print("position" in n) # Prints "True".
+ print("other_property" in n) # Prints "False".
+ [/codeblock]
Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See [method _notification].
</description>
<tutorials>
@@ -93,12 +99,12 @@
</description>
</method>
<method name="call_deferred" qualifiers="vararg">
- <return type="Variant">
+ <return type="void">
</return>
<argument index="0" name="method" type="String">
</argument>
<description>
- Calls the [code]method[/code] on the object during idle time and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
+ Calls the [code]method[/code] on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
[codeblock]
call_deferred("set", "position", Vector2(42.0, 0.0))
[/codeblock]
@@ -139,7 +145,7 @@
<argument index="4" name="flags" type="int" default="0">
</argument>
<description>
- Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants.
+ Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. These parameters will be passed to the method after any parameter used in the call to [method emit_signal]. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants.
A [code]signal[/code] can only be connected once to a [code]method[/code]. It will throw an error if already connected, unless the signal was connected with [constant CONNECT_REFERENCE_COUNTED]. To avoid this, first, use [method is_connected] to check for existing connections.
If the [code]target[/code] is destroyed in the game's lifecycle, the connection will be lost.
Examples:
@@ -148,6 +154,13 @@
connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
[/codeblock]
+ An example of the relationship between [code]binds[/code] passed to [method connect] and parameters used when calling [method emit_signal]:
+ [codeblock]
+ connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
+ emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
+ func _on_Player_hit(hit_by, level, weapon_type, damage):
+ print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
+ [/codeblock]
</description>
</method>
<method name="disconnect">
@@ -165,7 +178,7 @@
</description>
</method>
<method name="emit_signal" qualifiers="vararg">
- <return type="Variant">
+ <return type="void">
</return>
<argument index="0" name="signal" type="String">
</argument>
@@ -190,7 +203,7 @@
<argument index="0" name="property" type="String">
</argument>
<description>
- Returns the [Variant] value of the given [code]property[/code].
+ Returns the [Variant] value of the given [code]property[/code]. If the [code]property[/code] doesn't exist, this will return [code]null[/code].
</description>
</method>
<method name="get_class" qualifiers="const">
@@ -447,6 +460,7 @@
</argument>
<description>
Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
+ If the object already had a script, the previous script instance will be freed and its variables and state will be lost. The new script's [method _init] method will be called.
</description>
</method>
<method name="to_string">