Difference between revisions of "SHIP:Sail:getChild"

From Serious Documentation
Jump to: navigation, search
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
See Also:
+
{{SailFuncTableStart|}}<onlyinclude>
*[[SHIP:Sail|SHIP Sail Home]]
+
|{{SailFunc|getChild}}||{{DataType|Node}}||style="text-align:center;"|v4.0||Gets a child {{DataType|Node}} object from within an enclosing parent {{DataType|Node}}, by index.</onlyinclude>
*[[SHIP:Sail:Functions|SHIP Sail Function Home]]
+
|}
*[[SHIP:Sail:getChildCount |getChildCount()]], [[SHIP:Sail:getChildIndex |getChildIndex()]]
+
== See Also: ==
 
+
*[[SHIP:Sail|Sail Home]]
== getChild ==
+
*[[SHIP:Sail:Functions|Sail Functions]]
Gets a child node object from within an enclosing parent node, by index.
+
*[[SHIP:Sail:Node Functions|Sail Node Functions]]
 
+
*{{SailFunc|getChildCount}}, {{SailFunc|getChildIndex}}
 
== Prototype ==
 
== Prototype ==
<code>{{DataType|Node}} getChild({{DataType|Node}} parentNode, {{DataType|Integer}} index);</code>
+
<code>{{DataType|Node}} {{SailFunc|getChild}}({{DataType|Node}} parentNode, {{DataType|Integer}} index);</code>
 
 
 
=== Parameters/Return Value ===
 
=== Parameters/Return Value ===
 
{| class="wikitable" style="margin: 1em 1em;"  
 
{| class="wikitable" style="margin: 1em 1em;"  
Line 28: Line 27:
 
== Detailed Description ==
 
== Detailed Description ==
  
The <code>getChild(parent, index)</code> function returns the direct child at <code>index</code> within the parent.
+
The {{SailFunc|getChild}} function returns the direct child at <code>index</code> within the parent.
  
 
Nodes in [[SHIP]] may have 0 or more direct child nodes.  For example, a {{Node|group}} in the {{Node|resources}} area may have N {{Node|image}}s within the {{Node|group}}. These children, if present, are implicitly numbered <code>0..(N-1)</code> where <code>N</code> is the total number of children of any type within the parent node.  
 
Nodes in [[SHIP]] may have 0 or more direct child nodes.  For example, a {{Node|group}} in the {{Node|resources}} area may have N {{Node|image}}s within the {{Node|group}}. These children, if present, are implicitly numbered <code>0..(N-1)</code> where <code>N</code> is the total number of children of any type within the parent node.  
Line 37: Line 36:
  
 
== Examples ==
 
== Examples ==
 +
 +
=== Animations ===
 +
{{SailFunc|getChild}} is particularly useful for animations where an incrementing counter variable from a timer can be used as an index into a {{Node|group}} of {{Node|image}}s and then assigning the result to a {{Node|box}}'s {{Prop|box|object}} property.
 +
 +
 +
[[Category:Node Functions]]

Latest revision as of 17:53, 14 December 2016

Function Returns Introduced Description
getChild Node v4.0 Gets a child Node object from within an enclosing parent Node, by index.

See Also:

Prototype

Node getChild(Node parentNode, Integer index);

Parameters/Return Value

Parameter Data Type Description
parentNode Node The node to look in for children
index Integer The index of the child desired in the parent
Return Node nth node within the parentNode's children

Detailed Description

The getChild function returns the direct child at index within the parent.

Nodes in SHIP may have 0 or more direct child nodes. For example, a group in the resources area may have N images within the group. These children, if present, are implicitly numbered 0..(N-1) where N is the total number of children of any type within the parent node.

The index is always taken "modulus the count of children within the parent", preventing inadvertent out-of-bounds accesses. For example, a reference to index 5 when the parent only has 4 children will return 5%4 => 1. Negative indices are handled also with a modulus. Therefore, as expected, index -1 returns the last child.

If the specified parent node has no children, the parent object itself is returned by the function.

Examples

Animations

getChild is particularly useful for animations where an incrementing counter variable from a timer can be used as an index into a group of images and then assigning the result to a box's object property.