How can I toggle/cycle through settings?

Solution 1:

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