From b33c3fa0920ef7f2394050eab8ed72c3576ee416 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 5 Jul 2023 20:13:53 +0300 Subject: [PATCH] Update typed arrays documentation --- doc/classes/Array.xml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index bed9768603a5..ad8c0594e91d 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -57,7 +57,30 @@ - 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] @@ -317,19 +340,19 @@ - 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]. - 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. - 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].