Made get_child support negative indexes, with documentation
This commit is contained in:
parent
603febdbfe
commit
bdf614d3d7
2 changed files with 4 additions and 0 deletions
|
@ -213,6 +213,7 @@
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Returns a child node by its index (see [method get_child_count]). This method is often used for iterating all children of a node.
|
Returns a child node by its index (see [method get_child_count]). This method is often used for iterating all children of a node.
|
||||||
|
Negative indices access the children from the last one.
|
||||||
To access a child node via its name, use [method get_node].
|
To access a child node via its name, use [method get_node].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
|
|
@ -1327,6 +1327,9 @@ int Node::get_child_count() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *Node::get_child(int p_index) const {
|
Node *Node::get_child(int p_index) const {
|
||||||
|
if (p_index < 0) {
|
||||||
|
p_index += data.children.size();
|
||||||
|
}
|
||||||
ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr);
|
ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr);
|
||||||
|
|
||||||
return data.children[p_index];
|
return data.children[p_index];
|
||||||
|
|
Loading…
Reference in a new issue