getRootElement | Multi Theft Auto: Wiki Skip to content

getRootElement

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function returns the root node of the element tree, called root. This node contains every other element: all resource root elements, players and remote clients. It is never destroyed and cannot be destroyed using destroyElement.

Note

All resources have a predefined global variable called root that has the root element as value. The variable exists server side as well as client side.

Syntax

getRootElement ( )

Code Examples

server

This example will output the number of loaded resources by countingresourceelements that are children of therootnode.

--By default, predefined variable 'root' is getRootElement()
local rootChildren = getElementChildren( root )
local resourceCount = 0
for k, child in ipairs( rootChildren ) do
if getElementType( child ) == "resource" then
resourceCount = resourceCount + 1
end
end
outputChatBox( "There are " .. resourceCount .. " loaded resources." )

See Also

Element Functions