GetElementChildrenCount: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This | This function returns the number of children an element has. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
int getElementChildrenCount ( element parent ) | int getElementChildrenCount ( element parent ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''parent:''' the parent element | ||
=== | ===Returns=== | ||
Returns the number of child elements, or false if the parent element is invalid. | |||
=== | ==Example== | ||
To get the number of elements under team1: | |||
<syntaxhighlight lang="lua"> | |||
<team1 id="red"> | |||
<spawnpoint id="spawnpoint_0" posX="2507.8715820313" posY="2772.6071777344" posZ="10.8203125" rot="270" skin="285"/> | |||
<spawnpoint id="spawnpoint_1" posX="2508.060546875" posY="2780.3647460938" posZ="10.8203125" rot="270" skin="285"/> | |||
<spawnpoint id="spawnpoint_2" posX="2508.0053710938" posY="2776.2897949219" posZ="10.8203125" rot="270" skin="285"/> | |||
<spawnpoint id="spawnpoint_3" posX="2510.6899414063" posY="2778.3745117188" posZ="10.8203125" rot="270" skin="285"/> | |||
</team1></syntaxhighlight> | |||
You could use the following code: | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | teamRed = getElementByID ( "red" ) -- find the parent element by it's ID | ||
count = getElementChildrenCount ( teamRed ) -- get the total number of children | |||
outputChatBox ( "Team red has " .. count .. " spawnpoints" ) -- output: Team red has 4 spawnpoints | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{FunctionArea_Functions}} | {{FunctionArea_Functions}} |
Revision as of 12:17, 2 June 2006
This function returns the number of children an element has.
Syntax
int getElementChildrenCount ( element parent )
Required Arguments
- parent: the parent element
Returns
Returns the number of child elements, or false if the parent element is invalid.
Example
To get the number of elements under team1:
<team1 id="red"> <spawnpoint id="spawnpoint_0" posX="2507.8715820313" posY="2772.6071777344" posZ="10.8203125" rot="270" skin="285"/> <spawnpoint id="spawnpoint_1" posX="2508.060546875" posY="2780.3647460938" posZ="10.8203125" rot="270" skin="285"/> <spawnpoint id="spawnpoint_2" posX="2508.0053710938" posY="2776.2897949219" posZ="10.8203125" rot="270" skin="285"/> <spawnpoint id="spawnpoint_3" posX="2510.6899414063" posY="2778.3745117188" posZ="10.8203125" rot="270" skin="285"/> </team1>
You could use the following code:
teamRed = getElementByID ( "red" ) -- find the parent element by it's ID count = getElementChildrenCount ( teamRed ) -- get the total number of children outputChatBox ( "Team red has " .. count .. " spawnpoints" ) -- output: Team red has 4 spawnpoints