You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #43398 from KoBeWi/add_an_array_to_another_array_but_with_a_method
Add append_array() method to Array class
This commit is contained in:
@@ -192,6 +192,11 @@ void Array::push_back(const Variant &p_value) {
|
|||||||
_p->array.push_back(p_value);
|
_p->array.push_back(p_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Array::append_array(const Array &p_array) {
|
||||||
|
ERR_FAIL_COND(!_p->typed.validate(p_array, "append_array"));
|
||||||
|
_p->array.append_array(p_array._p->array);
|
||||||
|
}
|
||||||
|
|
||||||
Error Array::resize(int p_new_size) {
|
Error Array::resize(int p_new_size) {
|
||||||
return _p->array.resize(p_new_size);
|
return _p->array.resize(p_new_size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ public:
|
|||||||
|
|
||||||
void push_back(const Variant &p_value);
|
void push_back(const Variant &p_value);
|
||||||
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
|
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
|
||||||
|
void append_array(const Array &p_array);
|
||||||
Error resize(int p_new_size);
|
Error resize(int p_new_size);
|
||||||
|
|
||||||
void insert(int p_pos, const Variant &p_value);
|
void insert(int p_pos, const Variant &p_value);
|
||||||
|
|||||||
@@ -1356,6 +1356,7 @@ void Variant::_register_variant_methods() {
|
|||||||
bind_method(Array, push_back, sarray("value"), varray());
|
bind_method(Array, push_back, sarray("value"), varray());
|
||||||
bind_method(Array, push_front, sarray("value"), varray());
|
bind_method(Array, push_front, sarray("value"), varray());
|
||||||
bind_method(Array, append, sarray("value"), varray());
|
bind_method(Array, append, sarray("value"), varray());
|
||||||
|
bind_method(Array, append_array, sarray("array"), varray());
|
||||||
bind_method(Array, resize, sarray("size"), varray());
|
bind_method(Array, resize, sarray("size"), varray());
|
||||||
bind_method(Array, insert, sarray("position", "value"), varray());
|
bind_method(Array, insert, sarray("position", "value"), varray());
|
||||||
bind_method(Array, remove, sarray("position"), varray());
|
bind_method(Array, remove, sarray("position"), varray());
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
GD.Print(array1 + array2); // Prints [One, 2, 3, Four]
|
GD.Print(array1 + array2); // Prints [One, 2, 3, Four]
|
||||||
[/csharp]
|
[/csharp]
|
||||||
[/codeblocks]
|
[/codeblocks]
|
||||||
|
Note that concatenating with [code]+=[/code] operator will create a new array. If you want to append another array to an existing array, [method append_array] is more efficient.
|
||||||
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
|
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
@@ -149,6 +150,21 @@
|
|||||||
Appends an element at the end of the array (alias of [method push_back]).
|
Appends an element at the end of the array (alias of [method push_back]).
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="append_array">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="array" type="Array">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Appends another array at the end of this array.
|
||||||
|
[codeblock]
|
||||||
|
var array1 = [1, 2, 3]
|
||||||
|
var array2 = [4, 5, 6]
|
||||||
|
array1.append_array(array2)
|
||||||
|
print(array1) # Prints [1, 2, 3, 4, 5, 6].
|
||||||
|
[/codeblock]
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="back">
|
<method name="back">
|
||||||
<return type="Variant">
|
<return type="Variant">
|
||||||
</return>
|
</return>
|
||||||
|
|||||||
Reference in New Issue
Block a user