LoadMapData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (add new example) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
{{Server function}} | |||
__NOTOC__ | |||
__NOTOC__ | This function is intended to load data from a loaded XML file into the element tree. This could be used for loading an external map, or part of another map. | ||
This | |||
==Syntax== | ==Syntax== | ||
Line 10: | Line 9: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''node:''' The node that you wish to load into the [[element tree]]. | ||
*'''parent:''' The node you wish to be the parent of the new map data. | |||
*''' | |||
===Returns=== | ===Returns=== | ||
Returns '' | Returns an [[element]] object that corresponds to the root of the new data added, i.e. an element that represents the ''node'' xmlnode passed to the function. Returns ''false'' if the arguments are invalid. | ||
==Example== | ==Example== | ||
This example | '''Example 1:''' This example is a function that you could use to load an arbitary [https://forum.mtasa.com/topic/126081-map-files map file] into the [[element tree]]. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function loadMapFile(fileName) | ||
local xmlNode = getResourceConfig(fileName) | |||
-- | |||
if (xmlNode) then -- check if the file was loaded ok | |||
loadMapData(xmlNode, root) -- load the loaded xml file into the element tree | |||
xmlUnloadFile(xmlNode) -- Unload the xml file | |||
end | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Example 2:''' This example will destory the loaded map data after 30 seconds. | |||
<syntaxhighlight lang="lua"> | |||
function loadMapFile(fileName) | |||
local xmlNode = getResourceConfig(fileName) | |||
if (xmlNode) then -- check if the file was loaded ok | |||
nodeElement = loadMapData(xmlNode, root) -- load the loaded xml file into the element tree | |||
xmlUnloadFile(xmlNode) -- Unload the xml file | |||
end | |||
end | |||
setTimer(function() | |||
destroyElement(nodeElement) | |||
end,30000,1) | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{ | {{Map_functions}} |
Latest revision as of 09:15, 17 August 2024
This function is intended to load data from a loaded XML file into the element tree. This could be used for loading an external map, or part of another map.
Syntax
element loadMapData ( xmlnode node, element parent )
Required Arguments
- node: The node that you wish to load into the element tree.
- parent: The node you wish to be the parent of the new map data.
Returns
Returns an element object that corresponds to the root of the new data added, i.e. an element that represents the node xmlnode passed to the function. Returns false if the arguments are invalid.
Example
Example 1: This example is a function that you could use to load an arbitary map file into the element tree.
function loadMapFile(fileName) local xmlNode = getResourceConfig(fileName) if (xmlNode) then -- check if the file was loaded ok loadMapData(xmlNode, root) -- load the loaded xml file into the element tree xmlUnloadFile(xmlNode) -- Unload the xml file end end
Example 2: This example will destory the loaded map data after 30 seconds.
function loadMapFile(fileName) local xmlNode = getResourceConfig(fileName) if (xmlNode) then -- check if the file was loaded ok nodeElement = loadMapData(xmlNode, root) -- load the loaded xml file into the element tree xmlUnloadFile(xmlNode) -- Unload the xml file end end setTimer(function() destroyElement(nodeElement) end,30000,1)
See Also