Alias: Difference between revisions
(Added more explanation on what an alias is. Added section Usage. Mentioned incrementvar and multvar for one example. Added comments about +/- commands. Did some rewording.) |
No edit summary |
||
Line 1: | Line 1: | ||
{{langsp}} | {{langsp}} | ||
{{ | {{code|'''alias'''}} is a [[Developer console|console]] command that defines an alias for one or several commands. | ||
Aliases will only act for the engine session they were defined in. | Aliases will only act for the engine session they were defined in. |
Revision as of 19:08, 30 July 2023


alias is a console command that defines an alias for one or several commands.
Aliases will only act for the engine session they were defined in.
Usage
If no parameters are given, alias
will print a list of all aliases and their values.
Passing no command behaves like passing the empty command.
The first parameter is the alias name and all subsequent parameters are regarded as the command that the name will be associated with. Invoking the name of an alias like a command (after it has been defined with the alias command) will execute its associated command; Passing parameters has no effect.
The name of a new alias may not equal any existing console variable or console command. If the alias already exists, its associated command will be overwritten.
Examples
After running the command alias foo echo bar, typing foo in the console will execute echo bar.
After running the command alias foo, typing foo in the console will no longer do anything.
An example of an alias that toggles zoom. Running ZoomToggle will alternate between running +zoom and -zoom
An example of using aliases to increment/decrement the field of view.
Tip:In such cases, the commands incrementvar and multvar go without the definition of numerous aliases and therefore cause much less redundance:
Alias names may also use the prefixes + and -, see bind#Syntax. A common use of alias
is to change keybindings when a key is pressed or unpressed. For example, the following aliases can be used to make Alt+F4 exit the engine (whereas F4 alone will not):
Advanced Uses
Ignoring the limitation that there can only be a predefined maximum number of aliases, the alias
command alone makes the source console Turing complete. In other words, it is able to simulate any computer calculation, meaning a command can be run based on an arbitrarily complex way that aliased commands were invoked. For example, an alias can run another command if the amount of times the alias was invoked previously was prime. There are many uses that are more practical.
If the limit of a predefined maximum number of aliases is not ignored, the source console is only able to simulate a finite-state machine. However, due to how the alias
command can simulate a finite-state machine, it negates the typical drawback of mathematical operations requiring extremely large quantities of states. This is because, when the layer of abstraction to imagine a set of aliases as a finite-state machine is added, it is assumed that the results of inputs (contents of aliases) are not changed by default upon a transition. In other words, if state A dictates that input 1 will set the machine into state B, and input 2 of state A will set the machine into state C, then after invoking input 1, while the machine is indeed set to state B, inputs 1 and 2 still set the machine into states B and C, respectively, unless state B explicitly changes the functions of the inputs. The following example helps illustrate this:
Here, after state A is activated, followed by input 1 firing, the functions of inputs 1 and 2 persist after state B becomes the current state. This attribute of transitions persisting between states until redefined allows for enumerations. A set of binary enumerations may be used to store data, which may be manipulated according to logic, allowing for reasonably efficient mathematical operations and comparisons of any data type, such as integers, doubles, or floats, all of which may be signed or unsigned, and of any length. Compare the ability to store a 32-bit value with 32 binary enumerations to a traditional finite-state machine's requirement of 232 states to store an equivalent amount of data.