GetElementChild
Jump to navigation
Jump to search
This function returns an element based on it's parent. Without passing it to getElementType you won't know what type of element do you have though.
Syntax
element getElementChild ( element parent, int index )
Required Arguments
- parent: the element above the one to be returned in the hierarchy.
- index: the element's index (0 for the first element, 1 for the second, etc).
Returns
Returns the requested element if it exists, or false if it doesn't.
Example
If the .map file containts:
<team1 id="red"> <base name="Mountain Top" /> <base name="Docks" /> <base name="Airport" /> </team1>
This outputs the name of the specified base. For example: 'teamBase 0' for the first base.
function showTeamBase(player,command,index) local team = getElementByID("red") -- get the team element local base = getElementChild(team,tonumber(index)) -- get the Child of the element, based on the 'index' the player specified. if (base ~= false) then -- if a base exists outputChatBox("Team base "..index..": "..getElementData(base,"name"),player) -- output it to the player else outputChatBox("Base not found.",player) end end addCommandHandler("teamBase",showTeamBase)
Note that if there are other child elements, you'd have to check whether the element is a base. For example: 'teamBase 3' would output 'Team Base 3: Factory' with the .map file below, though it's no base.
<team1 id="red"> <base name="Mountain Top" /> <base name="Docks" /> <base name="Airport" /> <target name="Factory" /> </team1>
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