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 built-in data structure that holds a sequence of elements.
Description¶
An array data structure that can contain a sequence of elements of any type. Elements are accessed by a numerical index starting at 0. Negative indices are used to count from the back (-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: 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.
Informacja
There are notable differences when using this API with C#. See C# API differences to GDScript for more information.
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 |