Note Oct 2008: there has been changes and some of this now may not work, I will leave it here as some other VALVe Mods this still works...for now.
There are two great, infrequently used items in a scripting tool kit. Basically they are simple but very powerful binds.
The incrementvar and BindToggle binds and how they work are sometimes overlooked when people make their “old style” scripts, they save you a lot of effort and time, use them!
The incrementvar bind.
This is a great command and it’s got me beat why people are not using it!
I still see old methods used that take a far bit of writing to assemble and do the same job as this little beauty. Why? I guess it’s because it has not been explained just what the hell it can do :)
Description of the incrementvar command, the clue is in the commands name itself.... increment.
The word “increment” can mean a few things but in this case it means increasing or decreasing the value of a command.
The best thing about this is convenience, it can reduce a half a page of script to a simple bind.
Lets look at a simple task, I want to choose a netgraph type via a keyboard bind, there are four values for the net_graph command “0” – OFF, “1” “2” and “3” are the three types.
Let’s do this script the old way....
//My 1337 Netgraph script
alias ngraph "graph1"
alias ngraph1 "net_graph 1; alias ngraph ngraph2"
alias ngraph2 "net_graph 2; alias ngraph ngraph3"
alias ngraph3 "net_graph 3; alias ngraph ngraph4"
alias ngraph4 "net_graph 0; alias ngraph ngraph1"
bind "x" "ngraph"
As you can see it’s a normal script that uses an alias, bound to a key and when pressed, the alias and the command changes... resulting in the 4 settings in the net_graph command. It’s just the old Cycle script method.
Now let’s do it the new way...
bind "x" "incrementvar net_graph 0 3 1"
That’s it... finished, it does the same thing. The incrementvar command has turned this labor intensive task to something very simple!
The old style script I used above is a small one, imagine if it were a cycle script for the command “rate” if you wanted values of “rate 5000” to “rate 25000” in increments of 500.... it would go off this page. The new way would still look like the netgraph one above, just one short bind!
Let’s look at some advantages of the incrementvar command...
• It is easy to install, you can actually install this while in-game through the console, just like a regular bind.
• It is quicker to write when you have a lot of values to put in a script.
• It’s easy to trouble shoot if it goes wrong.
• You don’t have to have an autoexec.cfg or userconfig.cfg file, it installs in the standard config.cfg as a bind.
How about the disadvantages...
• Not everyone knows it exists.
• Not everyone knows how it works. How can you fix it if you don’t know how it works!
The first disadvantage is OK, let’s address that last one, how does it work.
bind "x" "incrementvar net_graph 0 3 1"....
• bind "x" ... this sets up the key we will use.
• "incrementvar ... the command needed to make a cycle script using a set of 3 numbers.
• net_graph ... the cvar, the net_graph command “0” – OFF, “1” “2” and “3” are the three types.
• 0 ... The first of the set of three numbers... this is the Minimum value, net_graph 0 turns the netgraph OFF.
• 3 ... The second of the set of three numbers... this is the Maximum value, net_graph 3.
• 1 ... The third of the set of three numbers... this is called the Delta value. In mathematics it is an incremental change in a variable.
What that Delta value means to us is the net_graph command will increase in increments of 1.
So how does it behave while in game?
You start a new game press your bind key once ....
The bind triggers net_graph “0” (netgraph OFF), press again, net_graph “1” (type 1), again net_graph “2” (type 2), then net_graph “3” (type 3), then back to net_graph “0”.
Now... if you didn’t want to start at netgraph “0” ... you can reverse it!
bind "x" "incrementvar net_graph 0 3 -1” ... Notice the ...-1” at the end this time? Now it will start from the Maximum value “3”, (net_graph 3) and work it’s way backwards to “0” (net_graph 0).
Now you know how it works you can fault find if you get it wrong.
Another thing to remember is you are not limited to the absolute lowest and highest value of a cvar, you pick that by setting the group of 3 numbers, first (low) and the second (high).
The Delta has two jobs, the increment number, the number can be 1 or 3 or whatever to divide into the Maximum evenly. The second job for the Delta is the setting or not setting the minus in front of it, to control the direction of the script cycle.
The BindToggle bind.
BindToggle is for those cvars that just have a ON “1” and OFF “0” valve. Look at this example below it is the command to make the minimap turn as you turn or stay locked.
BindToggle F12 overview_locked
It’s very simple to understand...
BindToggle F12 ... that part sets up the special bind and sets the key we will use.
The only other thing to add is the cvar ... overview_locked. Now you just press the key and it toggles through off and on.
That’s it. Very easy and like the incrementvar bind you can enter it in the console. The old way looked like this...
alias locmap " locmap on"
alias locmapon "overview_locked 1; alias locmap locmapoff"
alias locmapoff "overview_locked 0; alias locmap locmapon"
bind "F12" " locmap "
Now really... why make it that hard when these two are around :)
There is still a place for the alias type scripts, but they are for the more complex, multiple cvar types.
When you see some great big script in a forum somewhere that looks as big as a novel... quietly PM and send the Author of the huge 1337 script this page link :)