- Documentation
- Shared functions
- createElement
Function
createElement
Creates an element of your own type, e.g. "house" or "zone". It sits under the current resource root and disappears when the resource stops. Useful for grouping elements and storing data.
Syntax
element createElement(string elementType [, string elementID = nil])Arguments
elementTypestring- Type name.
elementIDstring, optional = nil- A text ID (for
getElementByID).
Returns
The new element or false.
Example
local house = createElement("house", "dom_grove_1")
setElementData(house, "price", 150000)
setElementData(house, "owner", false)
for _, h in ipairs(getElementsByType("house")) do
outputServerLog(getElementID(h) .. ": $" .. getElementData(h, "price"))
end
See also
getElementsByTypeReturns all elements of a type, optionally only under a given element (e.g.resourceRoot).setElementDataStores a value under a key on an element. By default the value is sent to all players, which firesonElementDataChange.setElementParentChanges the element's parent in the tree. Destroying the parent destroys the children too.isElementChecks whether a value is an existing element. Use it before acting on an element that may have been destroyed.destroyElementDestroys an element together with its children. On the client it also destroys GUI elements.