49
edits
| (18 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Sets an existing variable in the current context, reports variable value. | Sets an existing variable in the current context, reports variable value. | ||
<kua>bob fred</kua> | <kua>bob fred</kua> | ||
== Arguments == | |||
* name - name for variable to set | |||
* value (optional) - the value to set. If no value, then prints value if exists. | |||
== Associations == | == Associations == | ||
* Is the default command for the 'global' context. | * Is the default command for the 'global' context. | ||
* Does not have its own command name in 'global'. | * Does not have its own command name in 'global'. | ||
== Details == | == Details == | ||
Can be used to set or report a value for an existing variable. Will fail if variable does not already exist. | Can be used to set or report a value for an existing variable. Will fail if variable does not already exist. In 'global' context, 'name' and 'value' are used directly in a statement with no command name. | ||
Behaves like a combination of 'var' and 'set', but will never create a variable: | |||
* varedit - | * varedit - Never creates a variable, and sets anytime variable already exists. | ||
* var - | * var - Will create and set a variable, only if the variable does not yet exist. | ||
* set - | * set - Will create or set a variable, any time. | ||
== Examples == | == Examples == | ||
=== Default values === | === Default values === | ||
<kua> | <kua> | ||
> bob | > bob | ||
Unknown: bob | Unknown: bob | ||
</kua> | </kua> | ||
No 'bob' in the context. Variable 'bob' doesn't exist, and 'bob' is not the name of anything else. | |||
<kua> | <kua> | ||
> bob fred | > bob fred | ||
Unknown: bob | Unknown: bob | ||
</kua> | </kua> | ||
Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist. | |||
<kua> | <kua> | ||
> set bob fred | > set bob fred | ||
</kua> | </kua> | ||
Uses the 'set' command to create the variable 'bob' and set value to 'fred'. | |||
<kua> | <kua> | ||
> bob | > bob | ||
'bob' is 'fred' | 'bob' is 'fred' | ||
</kua> | </kua> | ||
Same as the first example, but now 'bob' exists. | |||
<kua> | <kua> | ||
> bob james | > bob james | ||
| Line 50: | Line 49: | ||
'bob' is 'james' | 'bob' is 'james' | ||
</kua> | </kua> | ||
Tries to set existing 'bob' to 'james', value changes. | |||
=== Change if exists === | === Change if exists === | ||
| Line 100: | Line 100: | ||
== Notes == | == Notes == | ||
* | * While 'varedit' is intended make console variable checking and editing easy, in combination with the other variable commands, can allow scripts and other types of macros to avoid lots of situations where complex logic would otherwise be required. | ||
* This default command 'varedit' would allow writing a script that was intended to only set certain variables if another service or module had already created them. | |||