hasElementData
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function checks if an element has element data available under a certain key.
OOP Syntax Help! I don't understand this!
- Method:element:hasData(...)
Syntax
bool hasElementData ( element theElement, string key, [ bool inherit = true ] )Required Arguments
- theElement: This is the element with data you want to check.
- key: The name of the element data entry you want to check for. (Maximum 31 characters.)
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- inherit (default: true): - toggles whether or not the function should go up the hierarchy to find the requested key in case the specified element doesn't have it.
Returns
- bool: value
This function returns true if the element contains element data for key , or false if the element doesn't exist or there is no data associated with the key .
Code Examples
shared
function favoriteAnimal ( source, commandName, playerName ) local thePlayer = source if playerName then -- see if a player was specified thePlayer = getPlayerFromName (playerName) -- get the player element for the specified player if not thePlayer then -- if we still couldn't find a player with the specified name... outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) -- display an error return end end
if hasElementData ( thePlayer, "favoriteAnimal" ) then -- check if the player has a favorite animal set local favoriteAnimal = getElementData ( thePlayer, "favoriteAnimal" ) -- get the player's favorite animal outputChatBox ( getPlayerName ( thePlayer ).."'s favorite animal is: "..favoriteAnimal, source ) -- output the player's favorite animal else outputChatBox ( getPlayerName ( thePlayer ).." does not have a favorite animal!", source ) -- output the player's lack of a favorite animal endend-- Add a console command joinTime, that takes an optional parameter of a player's nameaddCommandHandler ( "favoriteAnimal", favoriteAnimal )See Also
Element Functions
- addElementDataSubscriber
- attachElements
- clearElementVisibleTo
- cloneElement
- createElement
- destroyElement
- detachElements
- getAllElementData
- getAttachedElements
- getElementAlpha
- getElementAngularVelocity
- getElementAttachedOffsets
- getElementAttachedTo
- getElementBonePosition
- getElementBoneQuaternion
- getElementBoneRotation
- getElementBoundingBox
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getElementDimension
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementHealth
- getElementID
- getElementInterior
- getElementLighting
- getElementModel
- getElementParent
- getElementPosition
- getElementRadius
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementSyncer
- getElementType
- getElementVelocity
- getElementZoneName
- getLowLODElement
- getRootElement
- hasElementData
- hasElementDataSubscriber
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementCollidableWith
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLocal
- isElementLowLOD
- isElementOnFire
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementVisibleTo
- isElementWaitingForGroundToLoad
- isElementWithinColShape
- isElementWithinMarker
- removeElementData
- removeElementDataSubscriber
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementBonePosition
- setElementBoneQuaternion
- setElementBoneRotation
- setElementCallPropagationEnabled
- setElementCollidableWith
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementLighting
- setElementModel
- setElementOnFire
- setElementParent
- setElementPosition
- setElementRotation
- setElementStreamable
- setElementSyncer
- setElementVelocity
- setElementVisibleTo
- setLowLODElement
- updateElementRpHAnim
Element Events
- onClientElementColShapeHit
- onClientElementColShapeLeave
- onClientElementDataChange
- onClientElementDestroy
- onClientElementDimensionChange
- onClientElementInteriorChange
- onClientElementModelChange
- onClientElementStreamIn
- onClientElementStreamOut
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync