GetResourceDynamicElementRoot: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Add missing OOP info) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server client function}} | ||
This function retrieves the ''dynamic element root'' of a specified [[resource]]. The ''dynamic element root'' is the parent of elements that are created by scripts (e.g. with [[createObject]]) unless they specify a different parent. | This function retrieves the ''dynamic element root'' of a specified [[resource]]. The ''dynamic element root'' is the parent of elements that are created by scripts (e.g. with [[createObject]]) unless they specify a different parent. | ||
==Syntax== | ==Syntax== | ||
Line 9: | Line 7: | ||
element getResourceDynamicElementRoot ( resource theResource ) | element getResourceDynamicElementRoot ( resource theResource ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[resource]]:getDynamicElementRoot|dynamicElementRoot}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 17: | Line 16: | ||
==Example== | ==Example== | ||
This example shows how to get all elements by specific type, created only by resource scripts (not maps). | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | -- We have some map files with many objects in our meta.xml. | ||
-- And we have some objects, created by some resource scripts. | |||
-- createObject(...) -- 1 | |||
-- createObject(...) -- 2 | |||
-- ... | |||
-- createObject(...) -- 20 | |||
-- After resource start we must found all objects, created only | |||
-- by current resource scripts (not maps) and make them invisible. | |||
-- `resourceRoot` is predefined script variable containing current resource root pointer | |||
addEventHandler( 'onResourceStart', resourceRoot, | |||
function() | |||
-- `resource` is predefined script variable containing current resource pointer | |||
local thisResourceDynamicRoot = getResourceDynamicElementRoot(resource) | |||
local onlyScriptObjects = getElementsByType( 'object', thisResourceDynamicRoot ) | |||
for scriptObject in ipairs(onlyScriptObjects) do | |||
setElementAlpha( scriptObject, 0 ) | |||
end | |||
end | |||
) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Resource_functions}} | {{Resource_functions}} | ||
Latest revision as of 13:46, 10 August 2021
This function retrieves the dynamic element root of a specified resource. The dynamic element root is the parent of elements that are created by scripts (e.g. with createObject) unless they specify a different parent.
Syntax
element getResourceDynamicElementRoot ( resource theResource )
OOP Syntax Help! I don't understand this!
- Method: resource:getDynamicElementRoot(...)
- Variable: .dynamicElementRoot
Required Arguments
- theResource: the resource of which dynamic element root we want.
Returns
Returns an element of the resource's dynamic element root if the resource specified was valid and active (currently running), false otherwise.
Example
This example shows how to get all elements by specific type, created only by resource scripts (not maps).
-- We have some map files with many objects in our meta.xml. -- And we have some objects, created by some resource scripts. -- createObject(...) -- 1 -- createObject(...) -- 2 -- ... -- createObject(...) -- 20 -- After resource start we must found all objects, created only -- by current resource scripts (not maps) and make them invisible. -- `resourceRoot` is predefined script variable containing current resource root pointer addEventHandler( 'onResourceStart', resourceRoot, function() -- `resource` is predefined script variable containing current resource pointer local thisResourceDynamicRoot = getResourceDynamicElementRoot(resource) local onlyScriptObjects = getElementsByType( 'object', thisResourceDynamicRoot ) for scriptObject in ipairs(onlyScriptObjects) do setElementAlpha( scriptObject, 0 ) end end )
See Also
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo