GetResourceConfig: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 16: Line 16:
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.
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==  
==Example==
In the example
<syntaxhighlight lang="lua">
function resourceStart ( resourcename )    --When the resource is started
    if ( resourcename == getThisResource () ) then    --if the resource is this one
        node = getResourceConfig( resourcename, "file.xml" )    --get the configuration file
        local subNode = xmlFindSubNode( node, "group", 1 )    --get a subnode in it
        outputChatBox( xmlNodeGetAttribute( node, "attr" ) )    --output its' the attributes value to chatbox.
    end
end
addEventHandler ( "onResourceStart", getRootElement(), resourceStart )
</syntaxhighlight>


==See Also==
==See Also==
{{Resource_functions}}
{{Resource_functions}}
[[Category:Incomplete]]
[[Category:Incomplete]]

Revision as of 09:23, 30 July 2007

This function is used to return the root node of a configuration file. Config files must be predefined in a resource's meta file.

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

In the example

function resourceStart ( resourcename )    --When the resource is started
    if ( resourcename == getThisResource () ) then    --if the resource is this one
        node = getResourceConfig( resourcename, "file.xml" )    --get the configuration file
        local subNode = xmlFindSubNode( node, "group", 1 )    --get a subnode in it
        outputChatBox( xmlNodeGetAttribute( node, "attr" ) )    --output its' the attributes value to chatbox.
    end
end
addEventHandler ( "onResourceStart", getRootElement(), resourceStart )

See Also