summaryrefslogtreecommitdiffstats
path: root/doc/classes/Array.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/Array.xml')
-rw-r--r--doc/classes/Array.xml32
1 files changed, 28 insertions, 4 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index fd5ba57615..a72ac60536 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -40,6 +40,7 @@
[/codeblocks]
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array that can be modified independently of the original array, use [method duplicate].
[b]Note:[/b] Erasing elements while iterating over arrays is [b]not[/b] supported and will result in unpredictable behavior.
+ [b]Differences between packed arrays, typed arrays, and untyped arrays:[/b] Packed arrays are generally faster to iterate on and modify compared to a typed array of the same type (e.g. [PackedInt64Array] versus [code]Array[int][/code]). Also, packed arrays consume less memory. As a downside, packed arrays are less flexible as they don't offer as many convenience methods such as [method Array.map]. Typed arrays are in turn faster to iterate on and modify than untyped arrays.
</description>
<tutorials>
</tutorials>
@@ -57,7 +58,30 @@
<param index="2" name="class_name" type="StringName" />
<param index="3" name="script" type="Variant" />
<description>
- Creates a typed array from the [param base] array.
+ Creates a typed array from the [param base] array. All arguments are required.
+ - [param type] is the built-in type as a [enum Variant.Type] constant, for example [constant TYPE_INT].
+ - [param class_name] is the [b]native[/b] class name, for example [Node]. If [param type] is not [constant TYPE_OBJECT], must be an empty string.
+ - [param script] is the associated script. Must be a [Script] instance or [code]null[/code].
+ Examples:
+ [codeblock]
+ class_name MyNode
+ extends Node
+
+ class MyClass:
+ pass
+
+ func _ready():
+ var a = Array([], TYPE_INT, &amp;"", null) # Array[int]
+ var b = Array([], TYPE_OBJECT, &amp;"Node", null) # Array[Node]
+ var c = Array([], TYPE_OBJECT, &amp;"Node", MyNode) # Array[MyNode]
+ var d = Array([], TYPE_OBJECT, &amp;"RefCounted", MyClass) # Array[MyClass]
+ [/codeblock]
+ [b]Note:[/b] This constructor can be useful if you want to create a typed array on the fly, but you are not required to use it. In GDScript you can use a temporary variable with the static type you need and then pass it:
+ [codeblock]
+ func _ready():
+ var a: Array[int] = []
+ some_func(a)
+ [/codeblock]
</description>
</constructor>
<constructor name="Array">
@@ -323,19 +347,19 @@
<method name="get_typed_builtin" qualifiers="const">
<return type="int" />
<description>
- Returns the [enum Variant.Type] constant for a typed array. If the [Array] is not typed, returns [constant TYPE_NIL].
+ Returns the built-in type of the typed array as a [enum Variant.Type] constant. If the array is not typed, returns [constant TYPE_NIL].
</description>
</method>
<method name="get_typed_class_name" qualifiers="const">
<return type="StringName" />
<description>
- Returns a class name of a typed [Array] of type [constant TYPE_OBJECT].
+ Returns the [b]native[/b] class name of the typed array if the built-in type is [constant TYPE_OBJECT]. Otherwise, this method returns an empty string.
</description>
</method>
<method name="get_typed_script" qualifiers="const">
<return type="Variant" />
<description>
- Returns the script associated with a typed array tied to a class name.
+ Returns the script associated with the typed array. This method returns a [Script] instance or [code]null[/code].
</description>
</method>
<method name="has" qualifiers="const" keywords="includes, contains">