Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Array¶
A generic array datatype.
Description¶
A generic array that can contain several elements of any type, accessible by a numerical index starting at 0. Negative indices can be used to count from the back, like in Python (-1 is the last element, -2 is the second to last, etc.).
Example:
var array = ["One", 2, 3, "Four"]
print(array[0]) # One.
print(array[2]) # 3.
print(array[-1]) # Four.
array[2] = "Three"
print(array[-2]) # Three.
var array = new Godot.Collections.Array{"One", 2, 3, "Four"};
GD.Print(array[0]); // One.
GD.Print(array[2]); // 3.
GD.Print(array[array.Count - 1]); // Four.
array[2] = "Three";
GD.Print(array[array.Count - 2]); // Three.
Arrays can be concatenated using the +
operator:
var array1 = ["One", 2]
var array2 = [3, "Four"]
print(array1 + array2) # ["One", 2, 3, "Four"]
// Array concatenation is not possible with C# arrays, but is with Godot.Collections.Array.
var array1 = new Godot.Collections.Array{"One", 2};
var array2 = new Godot.Collections.Array{3, "Four"};
GD.Print(array1 + array2); // Prints [One, 2, 3, Four]
Note: Concatenating with the +=
operator will create a new array, which has a cost. If you want to append another array to an existing array, append_array is more efficient.
Note: Arrays are always passed by reference. To get a copy of an array that can be modified independently of the original array, use duplicate.
Note: Erasing elements while iterating over arrays is not supported and will result in unpredictable behavior.
Constructors¶
Array ( ) |
|
Array ( Array base, int type, StringName class_name, Variant script ) |
|
Array ( PackedByteArray from ) |
|
Array ( PackedColorArray from ) |
|
Array ( PackedFloat32Array from ) |
|
Array ( PackedFloat64Array from ) |
|
Array ( PackedInt32Array from ) |
|
Array ( PackedInt64Array from ) |
|
Array ( PackedStringArray from ) |
|
Array ( PackedVector2Array from ) |
|
Array ( PackedVector3Array from ) |
Methods¶
void |
|
void |
append_array ( Array array ) |
void |
|
back ( ) const |
|
bsearch_custom ( Variant value, Callable func, bool before=true ) const |
|
void |
clear ( ) |
void |
|
void |
|
front ( ) const |
|
get_typed_builtin ( ) const |
|
get_typed_class_name ( ) const |
|
get_typed_script ( ) const |
|
hash ( ) const |
|
is_empty ( ) const |
|
is_read_only ( ) const |
|
is_same_typed ( Array array ) const |
|
is_typed ( ) const |
|
void |
make_read_only ( ) |
max ( ) const |
|
min ( ) const |
|
pick_random ( ) const |
|
pop_back ( ) |
|
pop_front ( ) |
|
void |
|
void |
push_front ( Variant value ) |
void |
|
void |
reverse ( ) |
void |
shuffle ( ) |
size ( ) const |
|
slice ( int begin, int end=2147483647, int step=1, bool deep=false ) const |
|
void |
sort ( ) |
void |
sort_custom ( Callable func ) |
Operators¶
operator != ( Array right ) |
|
operator + ( Array right ) |
|
operator < ( Array right ) |
|
operator <= ( Array right ) |
|
operator == ( Array right ) |
|
operator > ( Array right ) |
|
operator >= ( Array right ) |
|
operator [] ( int index ) |
Constructor Descriptions¶
Array Array ( )
Constructs an empty Array.
Array Array ( Array base, int type, StringName class_name, Variant script )
Creates a typed array from the base
array.
Returns the same array as from
. If you need a copy of the array, use duplicate.
Array Array ( PackedByteArray from )
Constructs an array from a PackedByteArray.
Array Array ( PackedColorArray from )
Constructs an array from a PackedColorArray.
Array Array ( PackedFloat32Array from )
Constructs an array from a PackedFloat32Array.
Array Array ( PackedFloat64Array from )
Constructs an array from a PackedFloat64Array.
Array Array ( PackedInt32Array from )
Constructs an array from a PackedInt32Array.
Array Array ( PackedInt64Array from )
Constructs an array from a PackedInt64Array.
Array Array ( PackedStringArray from )
Constructs an array from a PackedStringArray.