GetElementChildren: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 22: | Line 22: | ||
<base name="Airport" /> | <base name="Airport" /> | ||
<anything name="no base" /> | <anything name="no base" /> | ||
</team1> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This example outputs the child elements of the element with id 'red', when the player enters the 'teamElements' command. | This example outputs the child elements of the element with id 'red', when the player enters the 'teamElements' command. |
Revision as of 14:49, 15 August 2007
This function is used to retrieve a list of child elements as they appear in the element table. Without passing each element in the table through getElementType, you won't know what you have though.
Syntax
table getElementChildren ( element parent )
Required Arguments
- parent: Supply this argument with the parent of the children you want returned.
Returns
This function returns a table that contains a list of elements that the parent has. If the element has no children, it will return an empy table. It will return false if the parent element does not exist.
Example
With this map file:
<team1 id="red"> <base name="Mountain Top" /> <base name="Docks" /> <base name="Airport" /> <anything name="no base" /> </team1>
This example outputs the child elements of the element with id 'red', when the player enters the 'teamElements' command.
function showTeamElements(player,command) local team = getElementByID("red") -- get the team element local elements = getElementChildren(team) -- the child elements for k,v in ipairs(elements) do outputChatBox(getElementType(v)..": "..getElementData(v,"name")) -- print the type and name of each child end end addCommandHandler("teamElements",showTeamElements)
At a later point you could loop through all the elements and process their contents any way you wish. Remember to make sure you have the CURRENT list of elements though. If you get the root element children, then wait a while for things to change, this list won't be up to date unless you use getElementChildren again.
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