Alias: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (removed vague and unhelpful line)
(changed extension of example file, gave more information on the command syntax, documented examples more)
Line 1: Line 1:
An alias is a [[Developer Console|console]] command that invokes other commands. Aliases will only act for the game session in which they are called upon in; however, binds in an alias can last if your config.cfg is not set to read only. It is common for aliases to be defined in the autoexec.cfg file, or, in the case of [[Team Fortress 2]], in the class config files that are executed when a class is chosen
'''<code>alias</code>''' is a [[Developer Console|console]] command that allows a specified command to invoke one or several other commands. Aliases will only act for the game session in which they are called upon 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 the autoexec.cfg file, or, in the case of [[Team Fortress 2]], in the class config files that are executed when a class is chosen.


== Examples ==
== Examples ==
alias "+ThirdPerson" "ThirdPerson"
After running the following command, typing <code>greet</code> in the console will execute <code>say hello!</code>
  alias "-ThirdPerson" "FirstPerson"
  alias greet "say hello!"


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


  alias "FoVx85" "FoV 85; alias FoVxIN FoVx85; alias FoVxOUT FoVx90"
An example of an alias that toggles zoom. running <code>ZoomToggle</code> will alternate between running <code>+zoom</code> and <code>-zoom</code>
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 <code>alias FoVxIN</code> makes the command <code>FoVxIN</code> no longer do anything
  alias "FoVx85" "FoV 85; alias FoVxIN       ; alias FoVxOUT FoVx90"
  alias "FoVx90" "FoV 90; alias FoVxIN FoVx85; alias FoVxOUT FoVx95"
  alias "FoVx90" "FoV 90; alias FoVxIN FoVx85; alias FoVxOUT FoVx95"
  alias "FoVx95" "FoV 95; alias FoVxIN FoVx90; alias FoVxOUT FoVx95"
  alias "FoVx95" "FoV 95; alias FoVxIN FoVx90; alias FoVxOUT"
  alias "FoVxIN" "FoVx90"
  alias "FoVxIN" "FoVx85"
  alias "FoVxOUT" "FoVx90"
  alias "FoVxOUT" "FoVx95"
 
 
A common use of <code>alias</code> is to run commands when a key is unpressed. for example, the following aliases can be used to test when <code>alt</code> is unpressed to allow <code>alt + f4</code> to exit the engine
bind alt "+alt_pressed"
alias +alt_pressed "bind f4 exit"
alias -alt_pressed "unbind f4"
 
 
{{warning|An alias doesn't work if the command it is set to invoke has quotation marks. ({{ent|alias}} does not support quotation marks inside quotation marks.)}}
{{warning|An alias doesn't work if the command it is set to invoke has quotation marks. ({{ent|alias}} does not support quotation marks inside quotation marks.)}}
  alias healthpls "ent_fire !self addoutput "health 200"" //does not work
  alias healthpls "ent_fire !self addoutput "health 200"" //does not work
{{workaround|Create a separate file containing that lone command and set alias to {{ent|exec}} the file.}}
{{workaround|Create a separate file containing that lone command and set alias to {{ent|exec}} the file.}}
  //This is the only line in file health_wrapper.cmd:
  //This is the only line in file health_wrapper.cfg:
  ent_fire !self addoutput "health 200"
  ent_fire !self addoutput "health 200"


  alias healthpls "exec health_wrapper.cmd" //works
  alias healthpls "exec health_wrapper.cfg" //works


== See Also ==
== See Also ==

Revision as of 19:35, 17 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 in which they are called upon 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 the autoexec.cfg file, or, in the case of Team Fortress 2, in the class config files that are executed when a class is chosen.

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 "FoVx85" "FoV 85; alias FoVxIN       ; alias FoVxOUT FoVx90"
alias "FoVx90" "FoV 90; alias FoVxIN FoVx85; alias FoVxOUT FoVx95"
alias "FoVx95" "FoV 95; alias FoVxIN FoVx90; alias FoVxOUT"
alias "FoVxIN"  "FoVx85"
alias "FoVxOUT" "FoVx95"


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 unpressed to allow alt + f4 to exit the engine

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


Warning.pngWarning:An alias doesn't work if the command it is set to invoke has quotation marks. (alias does not support quotation marks inside quotation marks.)
alias healthpls "ent_fire !self addoutput "health 200"" //does not work
PlacementTip.pngWorkaround:Create a separate file containing that lone command and set alias to exec the file.
//This is the only line in file health_wrapper.cfg:
ent_fire !self addoutput "health 200"
alias healthpls "exec health_wrapper.cfg" //works

See Also

Console Command List