HasElementData
Jump to navigation
Jump to search
This function checks if an element has element data available under a certain key.
Syntax
bool hasElementData ( element theElement, string key [, bool inherit = true] )
OOP Syntax Help! I don't understand this!
- Method: element:hasData(...)
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
- inherit: - 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
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.
Example
This example outputs a player's favorite animal using a console function 'favoriteAnimal' if they have one set.
Click to collapse [-]
Serverfunction favoriteAnimal ( source, commandName, playerName ) if ( playerName ) then -- see if a player was specified thePlayer = getPlayerFromName ( playerName ) -- get the player element for the specified player if ( thePlayer ) then -- if one was found... 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 end else outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) -- display an error end else if ( hasElementData ( source, "favoriteAnimal" ) ) then -- check if the player has a favorite animal set local favoriteAnimal = getElementData ( source, "favoriteAnimal" ) -- get the player's favorite animal outputChatBox ( "Your favorite animal is: "..favoriteAnimal, source ) -- output the player's favorite animal else outputChatBox ( "You do not have a favorite animal!", source ) -- output the player's lack of a favorite animal end end end -- Add a console command joinTime, that takes an optional parameter of a player's name addCommandHandler ( "favoriteAnimal", favoriteAnimal )
Requirements
This template will be deleted.
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