Engine:CCMD varedit: Difference between revisions
Line 12: | Line 12: | ||
== Details == | == Details == | ||
This is a 'default' command for the global context, and is used by simply using the 'name' and 'value' directly in a statement. It does not have a name in global to cal it by name. | |||
Can be used to set or report a value for an existing variable. Will fail if variable does not already exist. Behaves like a combination of 'var' and 'set', but will never create a variable: | |||
* varedit - Never creates variables, and sets anytime variable already exists. | * varedit - Never creates variables, and sets anytime variable already exists. | ||
* var - Creates and sets variables, only if the variable not yet exist. | * var - Creates and sets variables, only if the variable not yet exist. |
Revision as of 03:55, 14 October 2023
Sets an existing variable in the current context, reports variable value.
bob fred
Associations
- Is the default command for the 'global' context.
- Does not have its own command name in 'global'.
Arguments
- name - name for variable to set
- value (optional) - the value to set. If no value, then prints value if exists.
Details
This is a 'default' command for the global context, and is used by simply using the 'name' and 'value' directly in a statement. It does not have a name in global to cal it by name.
Can be used to set or report a value for an existing variable. Will fail if variable does not already exist. Behaves like a combination of 'var' and 'set', but will never create a variable:
- varedit - Never creates variables, and sets anytime variable already exists.
- var - Creates and sets variables, only if the variable not yet exist.
- set - Creates or sets variable, any time.
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.
For example, 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.
Examples
Default values
- 'bob' without a value. Variable 'bob' doesn't exist, and 'bob' is not the name of anything else.
> bob Unknown: bob
- Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist.
> bob fred Unknown: bob
- Using the 'set' command to create the variable 'bob' and set to 'fred'.
> set bob fred
- Same as the first example, but now 'bob' exists.
> bob
'bob' is 'fred'
- Try to set existing 'bob' to 'james', value changes.
> bob james
> bob
'bob' is 'james'
Change if exists
In this example let's pretend 'bob' is a Client module variable. Client when started will create 'bob' with a default value in the 'global' context.
- Variable 'bob' doesn't exist, and 'bob' is not the name of anything else.
> bob Unknown: bob
- Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist. Which is good.
> bob fred Unknown: bob
- Using the 'client' context run the Client 'start' command which will create the variable 'bob' with a default value of '8080'.
> client start
- Same as the first example, but now 'bob' exists.
> bob
'bob' is '8080'
- Try to set existing 'bob' to '8081', value changes.
> bob 8081
> bob
'bob' is '8081'
Macro
In this example 'bob' is still a Client module variable. We want to check the old value of bob before restarting the client.
- Check the value of bob. Stop the service. Then start client and then change the value after started. Client was not started previously.
> bob; client stop; client start; bob 8081; bob
Unknown: bob
Client not started.
Client started.
8081
- Same but Client fails to start, and removed or did not yet create the variable 'bob' before returning.
> bob; client stop; client start; bob 8081; bob
Unknown: bob
Client not started.
Client could not start.
Unknown: bob
Unknown: bob