Alias: Difference between revisions
m (cleaned up FOV example, explained what happens with lack of parameters) |
(Added section "Advanced uses", explaining that the alias command alone is Turing complete, and giving an example of a much more advanced use of the alias command.) |
||
Line 34: | Line 34: | ||
alias healthpls "exec health_wrapper.cfg" //works | alias healthpls "exec health_wrapper.cfg" //works | ||
== Advanced Uses == | |||
the <code>alias</code> command alone makes the source console [[Wikipedia:Turing_completeness|Turing complete]]. In other words, it is able to simulate any computer calculation, meaning a command can be run based on an arbitrarily complex set of alias calls. For example, an alias command can call another command if a different alias command was run ''n'' times, as long as ''n'' is prime. | |||
There are many uses that are more practical. | |||
== See Also == | == See Also == |
Revision as of 11:19, 30 June 2022
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 your config.cfg is not set to read only. It is common for aliases to be defined in configuration files.
If no parameters are given, alias
will print a list of all aliases and their values.
Examples
After running the following command, typing greet
in the console will execute say hello!
alias greet "say hello!"
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 FoVxIN
makes the command FoVxIN
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"

alias healthpls "ent_fire !self addoutput "health 200"" //does not work

//This is the only line in file health_wrapper.cfg: ent_fire !self addoutput "health 200"
alias healthpls "exec health_wrapper.cfg" //works
Advanced Uses
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 set of alias calls. For example, an alias command can call another command if a different alias command was run n times, as long as n is prime.
There are many uses that are more practical.