GetResourceConfig: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
 
(19 intermediate revisions by 11 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{server client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function is used to return the root node of a configuration file. Config files must be predefined in a resource's [[Meta.xml|meta file]].  An alternative way to load XML files is to use [[xmlLoadFile]].


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
returnType functionName ( arguments )
xmlnode getResourceConfig ( string filePath )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''filePath:''' The [[filepath]] of the file in the following format: '''":resourceName/path"'''. 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
*'''argumentName:''' description
:For example, if there is a file named 'settings.xml' in the resource 'ctf', it can be accessed from another resource this way: ''getResourceConfig(":ctf/settings.xml")''.
 
:If the file is in the current resource, only the file path is necessary, e.g. ''getResourceConfig("settings.xml")''.
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' description
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
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 ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==
<!-- Explain what the example is in a single sentance -->
<section name="Server" class="server" show="true">
This example does...
This example opens a configuration file and prints the value of the 'attr' attribute of the first 'group' node.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function resourceStart ( )                        -- When the resource is started
blabhalbalhb --abababa
    local node = getResourceConfig( "config.xml" )  -- get the configuration file
--This line does this...
    local subNode = xmlFindChild( node, "group", 0 )      -- get a subnode in it
mooo
    outputChatBox( xmlNodeGetAttribute( subNode, "attr" ),root )    -- output its attributes value to chatbox
end
addEventHandler ( "onResourceStart", resourceRoot, resourceStart )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Resource_functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 18:45, 29 April 2012

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 ( string filePath )

Required Arguments

  • filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
For example, if there is a file named 'settings.xml' in the resource 'ctf', it can be accessed from another resource this way: getResourceConfig(":ctf/settings.xml").
If the file is in the current resource, only the file path is necessary, e.g. getResourceConfig("settings.xml").

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

Click to collapse [-]
Server

This example opens a configuration file and prints the value of the 'attr' attribute of the first 'group' node.

function resourceStart ( )                         -- When the resource is started
    local node = getResourceConfig( "config.xml" )  -- get the configuration file
    local subNode = xmlFindChild( node, "group", 0 )      -- get a subnode in it
    outputChatBox( xmlNodeGetAttribute( subNode, "attr" ),root )    -- output its attributes value to chatbox
end
addEventHandler ( "onResourceStart", resourceRoot, resourceStart )

See Also

Shared