Engine:CCMD alias: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{dev/uiccmd}}
{{dev/uiccmd}}
Creates a new alias wiht a callable script in the current context, replacing existing alias if any.
Creates a new alias with a callable script in the current context, replacing existing alias if any.
<kua>alias bob "echo fred"</kua>
<kua>alias bob "echo fred"</kua>



Revision as of 23:54, 14 October 2023

Console commands

Creates a new alias with a callable script in the current context, replacing existing alias if any.

alias bob "echo fred"

Arguments

  • name - name for the new alias
  • value (optional) - script string or command to set as an alias. If not supplied, then prints the alias script value if the alias exists.

Associations

  • Is by default placed in the 'global' context.

Details

An 'alias' acts like a custom command. It runs the assigned text as a script, which can contain a single-word command, statement, or script. Is used to create a custom command in the current context.

Aliases do not have any parameters and will run the command, statement, or script verbatim. If for example, an alias named 'bob' is set to 'echo', it will always run exactly 'echo' which will print nothing, even if you run 'bob "some text". Here the second parameter was ignored.

Thus, aliases act like simple static macros. But when run they can do anything a script in the same context run by any other means could do. And because aliases are treated like commands, they can have direct key bindings.

Examples

Default values

  • Check alias 'bob' for script value. No alias exists named 'bob'.
> alias bob
Unknown: bob
  • Call 'bob'. No command, variable or alias named 'bob' exist.
> bob
Unknown: bob
  • Create an alias 'bob' and set to 'echo fred'.
> alias bob "echo fred"
  • Same as the second example, but now alias 'bob' exists. The 'echo' command in the 'bob' alias script runs, and prints 'fred'.
> bob
fred
  • Same as the first example, but now alias 'bob' exists and shows the value of the alias 'bob'
> alias bob
'bob' is 'echo fred'

To a variable

  • 'bob' called without a value. No command, variable or alias named 'bob' exist.
> bob
Unknown: bob
  • Create an alias 'bob' and set to 'fred'.
> alias bob fred
  • Same as the first example, but now alias 'bob' exists. The 'fred' command in the 'bob' alias script runs, and 'fred' doesn't exist.
> bob
Unknown: fred
  • Create variable 'fred'.
> var fred james
  • Run 'bob'
> bob
'fred' is 'james'
  • Try to set 'fred' through 'bob'. Value remains the same because 'bob' is only the statement "fred".
> bob alan
> bob
'fred' is 'james'

Notes