Merge pull request #79075 from dalexeev/doc-typed-arrays
Update typed arrays documentation
This commit is contained in:
commit
a27d9639f2
1 changed files with 27 additions and 4 deletions
|
@ -58,7 +58,30 @@
|
||||||
<param index="2" name="class_name" type="StringName" />
|
<param index="2" name="class_name" type="StringName" />
|
||||||
<param index="3" name="script" type="Variant" />
|
<param index="3" name="script" type="Variant" />
|
||||||
<description>
|
<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, &"", null) # Array[int]
|
||||||
|
var b = Array([], TYPE_OBJECT, &"Node", null) # Array[Node]
|
||||||
|
var c = Array([], TYPE_OBJECT, &"Node", MyNode) # Array[MyNode]
|
||||||
|
var d = Array([], TYPE_OBJECT, &"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>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="Array">
|
<constructor name="Array">
|
||||||
|
@ -324,19 +347,19 @@
|
||||||
<method name="get_typed_builtin" qualifiers="const">
|
<method name="get_typed_builtin" qualifiers="const">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<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>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_typed_class_name" qualifiers="const">
|
<method name="get_typed_class_name" qualifiers="const">
|
||||||
<return type="StringName" />
|
<return type="StringName" />
|
||||||
<description>
|
<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>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_typed_script" qualifiers="const">
|
<method name="get_typed_script" qualifiers="const">
|
||||||
<return type="Variant" />
|
<return type="Variant" />
|
||||||
<description>
|
<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>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="has" qualifiers="const" keywords="includes, contains">
|
<method name="has" qualifiers="const" keywords="includes, contains">
|
||||||
|
|
Loading…
Reference in a new issue