GetElementChildrenCount: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (|) |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This function returns the number of children an element has. | {{Server client function}} | ||
This function returns the number of children an element has. Note that only the direct children are counted and not elements that are further down the [[element tree]]. | |||
==Syntax== | ==Syntax== | ||
Line 8: | Line 7: | ||
int getElementChildrenCount ( element parent ) | int getElementChildrenCount ( element parent ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:getChildrenCount||}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 13: | Line 13: | ||
===Returns=== | ===Returns=== | ||
Returns the number of child elements, or false if the parent element | Returns an ''int'' with the number of child elements, or ''false'' if the parent element does not exist. | ||
==Example== | ==Example== | ||
To get the number of children the 'team1' element has: | To get the number of children the 'team1' element has: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="xml"> | ||
<team1 id="red"> | <team1 id="red"> | ||
<spawnpoint id="spawnpoint_0" posX="2507.8715820313" posY="2772.6071777344" posZ="10.8203125" rot="270" skin="285"/> | <spawnpoint id="spawnpoint_0" posX="2507.8715820313" posY="2772.6071777344" posZ="10.8203125" rot="270" skin="285"/> | ||
Line 27: | Line 27: | ||
You could use the following code: | You could use the following code: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
teamRed = getElementByID ( "red" ) -- find the parent element by | local teamRed = getElementByID("red") -- find the parent element by its ID | ||
count = getElementChildrenCount ( teamRed ) -- get the total number of children | local count = getElementChildrenCount (teamRed) -- get the total number of children | ||
outputChatBox ( "Team red has " .. count .. " spawnpoints" ) -- output: Team red has 4 spawnpoints | outputChatBox("Team red has " .. count .. " spawnpoints") -- output: Team red has 4 spawnpoints | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Note that this does not only count spawnpoint elements, but all child elements. Thus if there would be child elements of other types, the message would be wrong and you'd have to loop through the children manually, checking the type of each. | |||
==See Also== | ==See Also== | ||
{{ | {{Element_functions}} |
Latest revision as of 03:29, 1 January 2015
This function returns the number of children an element has. Note that only the direct children are counted and not elements that are further down the element tree.
Syntax
int getElementChildrenCount ( element parent )
OOP Syntax Help! I don't understand this!
- Method: element:getChildrenCount(...)
Required Arguments
- parent: the parent element
Returns
Returns an int with the number of child elements, or false if the parent element does not exist.
Example
To get the number of children the 'team1' element has:
<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:
local teamRed = getElementByID("red") -- find the parent element by its ID local count = getElementChildrenCount (teamRed) -- get the total number of children outputChatBox("Team red has " .. count .. " spawnpoints") -- output: Team red has 4 spawnpoints
Note that this does not only count spawnpoint elements, but all child elements. Thus if there would be child elements of other types, the message would be wrong and you'd have to loop through the children manually, checking the type of each.
See Also
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement