Alias: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(this section was very misguided as it stood, the example didn't work. I'll try to get around to adding something in its place. the way it really works is that quotation marks get removed and simply change how semicolons are parsed.)
m (changed state B in FSM example to actually require a separate alias to work to help show the utility of modeling alias logic as a finite-state machine.)
Line 33: Line 33:


  alias state_A "alias input_1 state_B; alias input_2 state_C; alias input_3 state_D"
  alias state_A "alias input_1 state_B; alias input_2 state_C; alias input_3 state_D"
  alias state_B "alias input_3 state_A"
  alias state_B "alias input_3 state_B"


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 2<sup>32</sup> states to store an equivalent amount of data.
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 2<sup>32</sup> states to store an equivalent amount of data.

Revision as of 09:20, 6 April 2023

alias is a console command that allows a specified command to invoke one or several other commands. Aliases will only act for the game session they were defined in. However, keys bound can last if config.cfg is not set to read-only.

If no parameters are given, alias will print a list of all aliases and their values.

Examples

After running the following command, typing foo in the console will execute echo bar

alias foo "echo bar"


An example of an alias that toggles zoom. running ZoomToggle will alternate between running +zoom and -zoom

alias "ZoomON"	   "+zoom; alias ZoomToggle ZoomOFF"
alias "ZoomOFF"    "-zoom; alias ZoomToggle ZoomON"
alias "ZoomToggle" "ZoomON"


An example of using aliases to increment/decrement the field of view. Note that running alias fovIN makes the command fovIN no longer do anything

alias "fov_85" "fov 85; alias fovIN;        alias fovOUT fov_90"
alias "fov_90" "fov 90; alias fovIN fov_85; alias fovOUT fov_95"
alias "fov_95" "fov 95; alias fovIN fov_90; alias fovOUT"
alias "fovIN"  "fov_85"
alias "fovOUT" "fov_95"


A common use of alias is to run commands when a key is unpressed. for example, the following aliases can be used to test when alt is pressed and unpressed to make alt+f4 exit the engine

bind alt "+alt_pressed"
alias +alt_pressed "bind f4 exit"
alias -alt_pressed "unbind f4"

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, and taking extremely long. 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. 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:

alias state_A "alias input_1 state_B; alias input_2 state_C; alias input_3 state_D"
alias state_B "alias input_3 state_B"

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.

See Also

Console Command List