XmlNodeSetAttribute: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Fix oop syntax)
 
(14 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
 
{{Server client function}}
__NOTOC__
This function is used to edit an attribute of a node in a configuration file.
This fake function is for use with blah & blah and does blahblahblabhalbhl


==Syntax==  
==Syntax==  
<syntaxhighlight lang="xml">
<syntaxhighlight lang="lua">
bool xmlNodeSetAttribute ( xmlnode xmlnode, string name, var value )             
bool xmlNodeSetAttribute ( xmlnode node, string name, string/float value )             
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[xmlnode]]:setAttribute||xmlNodeGetAttribute}}


===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''node:''' The node of which you wish to edit an attribute.
*'''name:''' The name of the attribute.
*'''value:''' The value which you wish to change the attribute to. ('''Note:''' ''nil'' will delete the attribute)


===Optional Arguments===  
===Returns===
{{OptionalArg}}
Returns ''true'' if the attribute was set successfully, ''false'' if the node and/or attribute do not exist, or if they're faulty.
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
==Example==
Returns ''true'' if blah, ''false'' otherwise.
<section name="Server" class="server" show="true">
In a gamemode, we want a command to change the marker color in the configuration file and remove a deprecated attribute.


==Example==
config.xml:
This example does...
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
--This line does...
<config>
blabhalbalhb --abababa
    <markers color="255,100,0" foo="deprecated" />
--This line does this...
</config>
mooo
</syntaxhighlight>
 
Lua code:
<syntaxhighlight lang="lua">
 
function changeConfigMarkerColor(thePlayer, command, r, g, b)
    local config = xmlLoadFile("config.xml")
    local markernode = xmlFindChild(config, "markers", 0)
    xmlNodeSetAttribute(markernode, "color", r .. "," .. g .. "," .. b)
    xmlNodeSetAttribute(markernode, "foo", nil) -- remove 'foo' attribute
    xmlSaveFile(config)
    xmlUnloadFile(config)
end
addCommandHandler("markercolor", changeConfigMarkerColor)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{XML_functions}}
[[ru:xmlNodeSetAttribute]]

Latest revision as of 14:50, 6 August 2016

This function is used to edit an attribute of a node in a configuration file.

Syntax

bool xmlNodeSetAttribute ( xmlnode node, string name, string/float value )             

OOP Syntax Help! I don't understand this!

Method: xmlnode:setAttribute(...)
Counterpart: xmlNodeGetAttribute


Required Arguments

  • node: The node of which you wish to edit an attribute.
  • name: The name of the attribute.
  • value: The value which you wish to change the attribute to. (Note: nil will delete the attribute)

Returns

Returns true if the attribute was set successfully, false if the node and/or attribute do not exist, or if they're faulty.

Example

Click to collapse [-]
Server

In a gamemode, we want a command to change the marker color in the configuration file and remove a deprecated attribute.

config.xml:

<config>
    <markers color="255,100,0" foo="deprecated" />
</config>

Lua code:


function changeConfigMarkerColor(thePlayer, command, r, g, b)
    local config = xmlLoadFile("config.xml")
    local markernode = xmlFindChild(config, "markers", 0)
    xmlNodeSetAttribute(markernode, "color", r .. "," .. g .. "," .. b)
    xmlNodeSetAttribute(markernode, "foo", nil) -- remove 'foo' attribute
    xmlSaveFile(config)
    xmlUnloadFile(config)
end
addCommandHandler("markercolor", changeConfigMarkerColor)

See Also