2,736
edits
Red Leader (talk | contribs) (→settimer(): Finish doc) |
Red Leader (talk | contribs) (→setprop(): Doc) |
||
| Line 2,032: | Line 2,032: | ||
=== setprop() === | === setprop() === | ||
Sets a property | {{Nasal doc | ||
|syntax = setprop(path[, path[, ...]], value); | |||
|source = {{flightgear file|src/Scripting/NasalSys.cxx|l=385|t=Source}} | |||
|text = Sets the value of a property in the [[Property Tree]]. If the property does not exist, it will be created. Returns 1 (true) on success or 0 (false) if there was an error. | |||
{{note|If you want to remove a property, you will have to use one of the <code>props</code> helpers: | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
props.globals.getNode("foo/bar").remove(); # take out the complete node | |||
props.globals.getNode("foo").removeChild("bar"); # take out a certain child node | |||
props.globals.getNode("foo/bar").remove(); | |||
props.globals.getNode("foo").removeChild("bar"); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
|param1 = path | |||
|param1text = There needs to be at least one '''path''' argument, but there is no limit to the maximum amount that can be given. They will be concatenated together to form a property tree path. The arguments must be strings, but in FlightGear v3.2 onwards, there also is support (added by {{flightgear commit|34ed79}}) for numeric arguments as indices. See example 2 below. | |||
|param2 = value | |||
|param2text = Value to write to the given property. Must be either a string or a number. | |||
|example1 = setprop("/sim/demo", "This is a demo"); | |||
|example2text = Note that the example below will only work in FlightGear 3.2 and above. | |||
|example2 = for(var i = 0; i < 3; i += 1){ | |||
setprop("/sim/demo", i, "Demo #" ~ i)); | |||
} | |||
|example3text = Same as above, but is supported by all versions of FlightGear. | |||
|example3 = for(var i = 0; i < 3; i += 1){ | |||
setprop("/sim/demo[" ~ i ~ "]", "Demo #" ~ i)); | |||
} | |||
}} | |||
=== settimer() === | === settimer() === | ||