Engine:CCMD varedit: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
 
(12 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'.
== Arguments ==
* name - name for variable to set
* value (optional) - the value to set. If no value, then prints value if exists.


== 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:
Behaves like a combination of 'var' and 'set', but will never create a variable:
Line 18: Line 18:
* var - Will create and set a variable, only if the variable does not yet exist.
* var - Will create and set a variable, only if the variable does not yet exist.
* set - Will create or set a variable, any time.
* set - Will create or set a 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 ==
== Examples ==
=== Default values ===
=== Default values ===
* 'bob' without a value. Variable 'bob' doesn't exist, and 'bob' is not the name of anything else.
<kua>
<kua>
> bob
> bob
Unknown: bob
Unknown: bob
</kua>
</kua>
* Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist.  
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>
* Using the 'set' command to create the variable 'bob' and set to 'fred'.  
Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist.
 
<kua>
<kua>
> set bob fred
> set bob fred
</kua>
</kua>
* Same as the first example, but now 'bob' exists.
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>
* Try to set existing 'bob' to 'james', value changes.  
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.

Latest revision as of 19:42, 14 October 2023

Console commands

Sets an existing variable in the current context, reports variable value.

bob fred

Arguments[edit]

  • name - name for variable to set
  • value (optional) - the value to set. If no value, then prints value if exists.

Associations[edit]

  • Is the default command for the 'global' context.
  • Does not have its own command name in 'global'.

Details[edit]

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 - Never creates a variable, and sets anytime variable already exists.
  • var - Will create and set a variable, only if the variable does not yet exist.
  • set - Will create or set a variable, any time.

Examples[edit]

Default values[edit]

> bob
Unknown: bob

No 'bob' in the context. Variable 'bob' doesn't exist, and 'bob' is not the name of anything else.

> bob fred
Unknown: bob

Tries to set variable 'bob' to 'fred'. Fails as 'bob' does not exist.

> set bob fred

Uses the 'set' command to create the variable 'bob' and set value to 'fred'.

> bob
'bob' is 'fred'

Same as the first example, but now 'bob' exists.

> bob james
> bob
'bob' is 'james'

Tries to set existing 'bob' to 'james', value changes.

Change if exists[edit]

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[edit]

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

Notes[edit]

  • 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.