Difference between revisions of "SHIP:Sail:getChild"

From Serious Documentation
Jump to: navigation, search
(Sail Function getChild)
(getChild)
Line 2: Line 2:
  
 
== getChild ==
 
== getChild ==
 +
 +
Gets a child node object from within an enclosing parent node, by index.
 +
 +
== Prototype ==
  
 
<code>node = getChild(parentNode, index);</code>
 
<code>node = getChild(parentNode, index);</code>
Line 19: Line 23:
 
! scope="col" style="text-align:left" | nth node within the parentNode's children
 
! scope="col" style="text-align:left" | nth node within the parentNode's children
 
|}
 
|}
 +
 +
== Detailed Description ==
 +
 +
Typically used for animation where
 +
 +
Nodes in [[SHIP]] may have 0 or more child nodes.  For example, a {{Node|group}} in the {{Node|resources}} area may have N {{Node|image}}s wihtin the {{Node|group}}.
 +
 +
These children, if present, are implicitly numbered <code>0..N-1</code>.
 +
 +
The <code>getChild</code> function returns the child at <code>index</code> within the parent.
 +
 +
The <code>index</code> is always taken "modulus the count of children within the parent", preventing inadvertent out-of-bounds accesses.  For example, a reference to index <code>5</code> when the parent only has <code>4</code> children will return <code>5%4 => 1</code>.  Negative indices are handled also with a modulus.  Therefore, as expected, index <code>-1</code> returns the last child.
 +
 +
If the specified parent node has no children, the parent object itself is returned by the function.
 +
 +
== Examples ==

Revision as of 16:49, 4 December 2012

SHIP Sail Reference Home

getChild

Gets a child node object from within an enclosing parent node, by index.

Prototype

node = getChild(parentNode, 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

Typically used for animation where

Nodes in SHIP may have 0 or more child nodes. For example, a group in the resources area may have N images wihtin the group.

These children, if present, are implicitly numbered 0..N-1.

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

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