feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -4,8 +4,7 @@
|
|||
A built-in data structure that holds a sequence of elements.
|
||||
</brief_description>
|
||||
<description>
|
||||
An array data structure that can contain a sequence of elements of any [Variant] 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.).
|
||||
[b]Example:[/b]
|
||||
An array data structure that can contain a sequence of elements of any [Variant] type. Elements are accessed by a numerical index starting at [code]0[/code]. Negative indices are used to count from the back ([code]-1[/code] is the last element, [code]-2[/code] is the second to last, etc.).
|
||||
[codeblocks]
|
||||
[gdscript]
|
||||
var array = ["First", 2, 3, "Last"]
|
||||
|
|
@ -18,14 +17,14 @@
|
|||
print(array[-3]) # Prints "Second"
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var array = new Godot.Collections.Array{"First", 2, 3, "Last"};
|
||||
Godot.Collections.Array array = ["First", 2, 3, "Last"];
|
||||
GD.Print(array[0]); // Prints "First"
|
||||
GD.Print(array[2]); // Prints 3
|
||||
GD.Print(array[array.Count - 1]); // Prints "Last"
|
||||
GD.Print(array[^1]); // Prints "Last"
|
||||
|
||||
array[2] = "Second";
|
||||
array[1] = "Second";
|
||||
GD.Print(array[1]); // Prints "Second"
|
||||
GD.Print(array[array.Count - 3]); // Prints "Second"
|
||||
GD.Print(array[^3]); // Prints "Second"
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
[b]Note:[/b] Arrays are always passed by [b]reference[/b]. To get a copy of an array that can be modified independently of the original array, use [method duplicate].
|
||||
|
|
@ -184,17 +183,17 @@
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Prints true (3/3 elements evaluate to true).
|
||||
// Prints True (3/3 elements evaluate to true).
|
||||
GD.Print(new Godot.Collections.Array>int< { 6, 10, 6 }.All(GreaterThan5));
|
||||
// Prints false (1/3 elements evaluate to true).
|
||||
// Prints False (1/3 elements evaluate to true).
|
||||
GD.Print(new Godot.Collections.Array>int< { 4, 10, 4 }.All(GreaterThan5));
|
||||
// Prints false (0/3 elements evaluate to true).
|
||||
// Prints False (0/3 elements evaluate to true).
|
||||
GD.Print(new Godot.Collections.Array>int< { 4, 4, 4 }.All(GreaterThan5));
|
||||
// Prints true (0/0 elements evaluate to true).
|
||||
// Prints True (0/0 elements evaluate to true).
|
||||
GD.Print(new Godot.Collections.Array>int< { }.All(GreaterThan5));
|
||||
|
||||
// Same as the first line above, but using a lambda function.
|
||||
GD.Print(new Godot.Collections.Array>int< { 6, 10, 6 }.All(element => element > 5)); // Prints true
|
||||
GD.Print(new Godot.Collections.Array>int< { 6, 10, 6 }.All(element => element > 5)); // Prints True
|
||||
}
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
|
|
@ -243,7 +242,7 @@
|
|||
var numbers = [1, 2, 3]
|
||||
var extra = [4, 5, 6]
|
||||
numbers.append_array(extra)
|
||||
print(nums) # Prints [1, 2, 3, 4, 5, 6]
|
||||
print(numbers) # Prints [1, 2, 3, 4, 5, 6]
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
|
|
@ -325,6 +324,7 @@
|
|||
<param index="0" name="value" type="Variant" />
|
||||
<description>
|
||||
Returns the number of times an element is in the array.
|
||||
To count how many elements in an array satisfy a condition, see [method reduce].
|
||||
</description>
|
||||
</method>
|
||||
<method name="duplicate" qualifiers="const">
|
||||
|
|
@ -358,7 +358,7 @@
|
|||
print(array) # Prints [2, 2, 2, 2, 2]
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var array = new Godot.Collections.Array();
|
||||
Godot.Collections.Array array = [];
|
||||
array.Resize(5);
|
||||
array.Fill(2);
|
||||
GD.Print(array); // Prints [2, 2, 2, 2, 2]
|
||||
|
|
@ -396,6 +396,25 @@
|
|||
[b]Note:[/b] For performance reasons, the search is affected by [param what]'s [enum Variant.Type]. For example, [code]7[/code] ([int]) and [code]7.0[/code] ([float]) are not considered equal for this method.
|
||||
</description>
|
||||
</method>
|
||||
<method name="find_custom" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="method" type="Callable" />
|
||||
<param index="1" name="from" type="int" default="0" />
|
||||
<description>
|
||||
Returns the index of the [b]first[/b] element in the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the end of the array.
|
||||
[param method] is a callable that takes an element of the array, and returns a [bool].
|
||||
[b]Note:[/b] If you just want to know whether the array contains [i]anything[/i] that satisfies [param method], use [method any].
|
||||
[codeblocks]
|
||||
[gdscript]
|
||||
func is_even(number):
|
||||
return number % 2 == 0
|
||||
|
||||
func _ready():
|
||||
print([1, 3, 4, 7].find_custom(is_even.bind())) # Prints 2
|
||||
[/gdscript]
|
||||
[/codeblocks]
|
||||
</description>
|
||||
</method>
|
||||
<method name="front" qualifiers="const">
|
||||
<return type="Variant" />
|
||||
<description>
|
||||
|
|
@ -403,6 +422,13 @@
|
|||
[b]Note:[/b] Unlike with the [code][][/code] operator ([code]array[0][/code]), an error is generated without stopping project execution.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Variant" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the element at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_typed_builtin" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
|
|
@ -434,12 +460,12 @@
|
|||
print(["inside", 7].has("7")) # Prints false
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var arr = new Godot.Collections.Array { "inside", 7 };
|
||||
Godot.Collections.Array arr = ["inside", 7];
|
||||
// By C# convention, this method is renamed to `Contains`.
|
||||
GD.Print(arr.Contains("inside")); // Prints true
|
||||
GD.Print(arr.Contains("outside")); // Prints false
|
||||
GD.Print(arr.Contains(7)); // Prints true
|
||||
GD.Print(arr.Contains("7")); // Prints false
|
||||
GD.Print(arr.Contains("inside")); // Prints True
|
||||
GD.Print(arr.Contains("outside")); // Prints False
|
||||
GD.Print(arr.Contains(7)); // Prints True
|
||||
GD.Print(arr.Contains("7")); // Prints False
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
In GDScript, this is equivalent to the [code]in[/code] operator:
|
||||
|
|
@ -547,7 +573,7 @@
|
|||
print([1, 2, 3.25, "Hi"].pick_random())
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var array = new Godot.Collections.Array { 1, 2, 3.25f, "Hi" };
|
||||
Godot.Collections.Array array = [1, 2, 3.25f, "Hi"];
|
||||
GD.Print(array.PickRandom()); // May print 1, 2, 3.25, or "Hi".
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
|
|
@ -611,15 +637,26 @@
|
|||
If [method max] is not desirable, this method may also be used to implement a custom comparator:
|
||||
[codeblock]
|
||||
func _ready():
|
||||
var arr = [Vector2(5, 0), Vector2(3, 4), Vector2(1, 2)]
|
||||
var arr = [Vector2i(5, 0), Vector2i(3, 4), Vector2i(1, 2)]
|
||||
|
||||
var longest_vec = arr.reduce(func(max, vec): return vec if is_length_greater(vec, max) else max)
|
||||
print(longest_vec) # Prints Vector2(3, 4).
|
||||
print(longest_vec) # Prints (3, 4)
|
||||
|
||||
func is_length_greater(a, b):
|
||||
return a.length() > b.length()
|
||||
[/codeblock]
|
||||
See also [method map], [method filter], [method any] and [method all].
|
||||
This method can also be used to count how many elements in an array satisfy a certain condition, similar to [method count]:
|
||||
[codeblock]
|
||||
func is_even(number):
|
||||
return number % 2 == 0
|
||||
|
||||
func _ready():
|
||||
var arr = [1, 2, 3, 4, 5]
|
||||
# If the current element is even, increment count, otherwise leave count the same.
|
||||
var even_count = arr.reduce(func(count, next): return count + 1 if is_even(next) else count, 0)
|
||||
print(even_count) # Prints 2
|
||||
[/codeblock]
|
||||
See also [method map], [method filter], [method any], and [method all].
|
||||
</description>
|
||||
</method>
|
||||
<method name="remove_at">
|
||||
|
|
@ -655,6 +692,22 @@
|
|||
Returns the index of the [b]last[/b] occurrence of [param what] in this array, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find].
|
||||
</description>
|
||||
</method>
|
||||
<method name="rfind_custom" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="method" type="Callable" />
|
||||
<param index="1" name="from" type="int" default="-1" />
|
||||
<description>
|
||||
Returns the index of the [b]last[/b] element of the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find_custom].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set">
|
||||
<return type="void" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<param index="1" name="value" type="Variant" />
|
||||
<description>
|
||||
Sets the value of the element at the given [param index] to the given [param value]. This will not change the size of the array, it only changes the value at an index already in the array. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="shuffle">
|
||||
<return type="void" />
|
||||
<description>
|
||||
|
|
@ -702,7 +755,7 @@
|
|||
print(numbers) # Prints [2.5, 5, 8, 10]
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var numbers = new Godot.Collections.Array { 10, 5, 2.5, 8 };
|
||||
Godot.Collections.Array numbers = [10, 5, 2.5, 8];
|
||||
numbers.Sort();
|
||||
GD.Print(numbers); // Prints [2.5, 5, 8, 10]
|
||||
[/csharp]
|
||||
|
|
@ -715,7 +768,7 @@
|
|||
<param index="0" name="func" type="Callable" />
|
||||
<description>
|
||||
Sorts the array using a custom [Callable].
|
||||
[param func] is called as many times as necessary, receiving two array elements as arguments. The function should return [code]true[/code] if the first element should be moved [i]behind[/i] the second one, otherwise it should return [code]false[/code].
|
||||
[param func] is called as many times as necessary, receiving two array elements as arguments. The function should return [code]true[/code] if the first element should be moved [i]before[/i] the second one, otherwise it should return [code]false[/code].
|
||||
[codeblock]
|
||||
func sort_ascending(a, b):
|
||||
if a[1] < b[1]:
|
||||
|
|
@ -728,7 +781,7 @@
|
|||
print(my_items) # Prints [["Rice", 4], ["Tomato", 5], ["Apple", 9]]
|
||||
|
||||
# Sort descending, using a lambda function.
|
||||
my_items.sort_custom(func(a, b): return a[0] > b[0])
|
||||
my_items.sort_custom(func(a, b): return a[1] > b[1])
|
||||
print(my_items) # Prints [["Apple", 9], ["Tomato", 5], ["Rice", 4]]
|
||||
[/codeblock]
|
||||
It may also be necessary to use this method to sort strings by natural order, with [method String.naturalnocasecmp_to], as in the following example:
|
||||
|
|
@ -764,8 +817,8 @@
|
|||
[/gdscript]
|
||||
[csharp]
|
||||
// Note that concatenation is not possible with C#'s native Array type.
|
||||
var array1 = new Godot.Collections.Array{"One", 2};
|
||||
var array2 = new Godot.Collections.Array{3, "Four"};
|
||||
Godot.Collections.Array array1 = ["One", 2];
|
||||
Godot.Collections.Array array2 = [3, "Four"];
|
||||
GD.Print(array1 + array2); // Prints ["One", 2, 3, "Four"]
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue