SetElementData: Difference between revisions
Dutchman101 (talk | contribs) mNo edit summary |
Dutchman101 (talk | contribs) m (Extended performance note) |
||
Line 8: | Line 8: | ||
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}} | {{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}} | ||
{{Note|See [[Script security]] for tips on preventing cheaters when using events and element data}} | {{Note|See [[Script security]] for tips on preventing cheaters when using events and element data}} | ||
{{Note|For performance reasons, never use setElementData in events that fire often (like [[onClientRender]]) without further optimization or conditions.}} | {{Note|For performance reasons, never use setElementData in events that fire often (like [[onClientRender]]) without further optimization or conditions. In fact, using element data in general can take such a toll on performance that not using it unless strictly neccesary (e.g use alternatives such as storing data in tables) is recommended.}}. | ||
Revision as of 00:33, 5 July 2020
This function stores element data under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.
As element data is synced to all clients, it can generate a lot of network traffic and be heavy on performance. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.
Usage of element data should be disencouraged where your goal can be achieved with events like above, and tables for storing and retrieving data.
Tip: A simple and efficient way to make a variable known to the server and clients is to use setElementData on the root element. |
.
Syntax
bool setElementData ( element theElement, string key, var value [, bool synchronize = true ] )
OOP Syntax Help! I don't understand this!
- Method: element:setData(...)
- Counterpart: getElementData
Required Arguments
- theElement: The element you wish to attach the data to.
- key: The key you wish to store the data under. (Maximum 31 characters.)
- value: The value you wish to store. See element data for a list of acceptable datatypes.
Optional Arguments
- synchronize: Determines whether or not the data will be synchronized with the clients(server-side variation) or server(client-side variation)
Returns
Returns true if the data was set succesfully, false otherwise.
Issues
Issue ID | Description |
---|---|
#7389 | [Fixed in 1.3.5-7389] Problem with floating numbers |
Example
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