GetResourceConfig: Difference between revisions
Jump to navigation
Jump to search
m (changed variable name to more accurate description) |
m (changed variable name to more accurate description) |
||
Line 20: | Line 20: | ||
This example opens a configuration file and prints the value of the 'attr' attribute of the first 'group' node. | This example opens a configuration file and prints the value of the 'attr' attribute of the first 'group' node. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function resourceStart ( | function resourceStart ( theResource ) -- When a resource is started | ||
if ( | if ( theResource == getThisResource () ) then -- and the resource is this one | ||
node = getResourceConfig( | node = getResourceConfig( theResource, "config.xml" ) -- get the configuration file | ||
local subNode = xmlFindSubNode( node, "group", 1 ) -- get a subnode in it | local subNode = xmlFindSubNode( node, "group", 1 ) -- get a subnode in it | ||
outputChatBox( xmlNodeGetAttribute( node, "attr" ) ) -- output its attributes value to chatbox | outputChatBox( xmlNodeGetAttribute( node, "attr" ) ) -- output its attributes value to chatbox |
Revision as of 03:40, 6 January 2008
This function is used to return the root node of a configuration file. Config files must be predefined in a resource's meta file. An alternative way to load XML files is to use xmlLoadFile.
Syntax
xmlnode getResourceConfig ( [resource theResource = getThisResource()], string filename )
Required Arguments
- filename: The exact file name of the configuration file. (e.g. "file.xml" )
Optional Arguments
- theResource: The resource from which the function calls the configuration file
Returns
Returns the root node of the specified configuration file. If the file is corrupted, not defined in the meta file or doesn't exist, returns false.
Example
This example opens a configuration file and prints the value of the 'attr' attribute of the first 'group' node.
function resourceStart ( theResource ) -- When a resource is started if ( theResource == getThisResource () ) then -- and the resource is this one node = getResourceConfig( theResource, "config.xml" ) -- get the configuration file local subNode = xmlFindSubNode( node, "group", 1 ) -- get a subnode in it outputChatBox( xmlNodeGetAttribute( node, "attr" ) ) -- output its attributes value to chatbox end end addEventHandler ( "onResourceStart", getRootElement(), resourceStart )