HU/getRootElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
{{Note|All resources have a [[Predefined_variables_list|predefined global variable]] called ''root'' that has the root element as value. The variable exists server side as well as client side.}}
{{Note|All resources have a [[Predefined_variables_list|predefined global variable]] called ''root'' that has the root element as value. The variable exists server side as well as client side.}}


==Syntax==
==Szintaxis==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getRootElement ( )
element getRootElement ( )
</syntaxhighlight>
</syntaxhighlight>


===Returns===
===Visszaadott érték===
Returns the root [[element]].
Returns the root [[element]].


==Example==
==Példa==
This example will output the number of loaded resources by counting ''resource'' elements that are children of the ''root'' node.
This example will output the number of loaded resources by counting ''resource'' elements that are children of the ''root'' node.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 30: Line 30:
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==Lásd még==
{{Element functions}}
{{Element functions}}
[[en:getRootElement]]
[[en:getRootElement]]
[[ru:getRootElement]]
[[ru:getRootElement]]
==Fordította==
Surge

Revision as of 14:01, 19 July 2018

Ez a függvény visszaadja az elemfa gyökér csomópontját, melyet root-nak hívnak. Ez a csomópont minden más elemet tartalmaz: minden resource gyökérelemet, játékosokat és távoli klienseket. Sosem lehet megsemmisíteni, még destroyElement használatával sem.

It is often used to attach handler functions to events triggered for any element, or also to make a scripting function affect all elements.

[[{{{image}}}|link=|]] 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.

Szintaxis

element getRootElement ( )

Visszaadott érték

Returns the root element.

Példa

This example will output the number of loaded resources by counting resource elements that are children of the root node.

--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." )

Lásd még

Fordította

Surge