How can I toggle/cycle through settings?

I want to be able to cycle through names, scripts
or source commands.

By cycling i mean switching to another name, script or command after i press a button. Pressing this button repeatedly will go through all those entries until the end where it will reach the first entry again.

  • What is this autoexec.cfg, and what does it do?
  • What is the gravity model in Source engine games?
  • Loadout unavailable on dedicated TF2 LAN server
  • How do you turn on “windowed fullscreen” in TF2 and other Source games?
  • How can I run a dedicated server without Steam?
  • Is there a way to measure distance between points in Source engine games?
  • For example if I have 3 nicknames A, B and C and want to cycle through those.

    Pressing a button shall execute a command that changes my name to B and after pressing the same button again my name will be changed to C. Pressing again will result in my name changing to A again, completing the cycle.

    How would a template for this look like?

  • How can I run a dedicated server without Steam?
  • How do I change the loaded map and config files on a rented Counter Strike: Global Offensive server?
  • Loadout unavailable on dedicated TF2 LAN server
  • How do you turn on “windowed fullscreen” in TF2 and other Source games?
  • What is the gravity model in Source engine games?
  • Is there a way to measure distance between points in Source engine games?
  • 2 Solutions collect form web for “How can I toggle/cycle through settings?”

    To cycle through different names/settings/scripts etc you need to follow the following pattern (At the end there is the full code if you want to skip the details):

    Cycling through self made scripts using alias

    Step 1: Set a starting point

    alias cycler "useName1"
    

    Now if we trigger cycler -> useName1 will be executed.

    cycler and useName1 are names i made up. You can change those to whatever fits your needs.

    Step 2: Define useName1 and set cycler

    alias useName1 "setinfo name "First_name"; alias cycler useName2"
    

    This will execute the namechange (or your script or your setting) and set the cycler to useName2. The next time we trigger cycler -> useName2 will be executed.

    useName2 is a name i made up too.

    Step 3: Define useName2 and set cycler

    alias useName2 "setinfo name "Second_name"; alias cycler useName1"
    

    This will execute the second namechange (or your script or your setting) and set the cycler back to useName1. The next time we trigger cycler -> useName1 will be executed again. The cycle is complete.

    Step 4: Bind your cycler to a key

    bind "key" cycler
    

    We are done. You can repeat part 2 and 3 for other definitions (if you switch through 15 names, go for it). Just let the last set the cycler onto the first!

    Full Code Solution 1

    alias cycler "useName1"
    alias useName1 "setinfo name "First_name"; alias cycler useName2"
    alias useName2 "setinfo name "Second_name"; alias cycler useName1"
    bind "key" cycler
    

    Cycling through settings provided by the source engine

    If you want to iterate through settings that are predefined by the source engine and require a number as a value, for example:

    net_graph x (value 0 to 3 are possible)
    sensitivity x (any value is possible)
    

    then you don’t need to use the cycler above.

    Instead source provides us with two nifty commands:

    Toggle

    toggle command value1 value2 value3

    This command let’s us cycle through the setting with specific values.

    For example:

    toggle net_graph 1 2 3

    Starts with executing net_graph 1. Using this command again executes net_graph 2 and so forth.

    To use this command quickly just go ahead and bind it to a key

    Full Code toggle

    bind "x" "toggle net_graph 1 2 3"

    Incrementvar

    incrementvar command min max steps

    This let’s us cycle through the setting in defined steps.

    For example:

    incrementvar net_graph 1 3 1

    Starts with net_graph 1 and increases each step +1. This means executing the command again results in net_graph 2. The next would be net_graph 3.
    After that it will jump back to net_graph 1 because we told him that the max value would be 3.

    The other example would be:

    incrementvar sensitivity 200 800 200

    which increases the sensitivity by 200 each time we execute this until it reaches 800 at which point it will drop to 200 again.

    The steps can be negative to (cycle backwards) like:

    incrementvar sensitivity 200 800 -200

    To use this command we still need to bind it:

    Full Code incrementvar

    bind "key" "incrementvar sensitivity 200 800 200"

    Another Solution

    Another solution to cycle through variables (settings,commands etc) would be to rebind the button directly.

    This however is discouraged since it takes more resources from the system while just changing an alias to another does not interfere with keymapping at all which is therefore quite static.

    Still I will show it for completeness

    Full Code Solution 2

    alias useName1 "setinfo name "First_name"; bind "key" useName2"
    alias useName2 "setinfo name "Second_name"; bind "key" useName1"
    bind "key" useName1
    

    Full Code Solution 2 – work fine WITHOUT setinfo

    alias useName1 "dota_spectator_mode "1"; bind "c" useName2"
    alias useName2 "dota_spectator_mode "3"; bind "c" useName1"
    bind "c" useName1
    
    We love Playing Games, especially Video Games.