logo Scripting for Enemy Territory

Menu


Home
Tutorials
Downloads
Forum
Contact

Friends





Basic tutorial 7

Variables (vstr).

Before you can actually start scripting you have to know how to use variables. In scripting we use variables to store information in, so that when we call that variable, we access the information stored in that variable. So logically we have to store something in a variable, before we can use it. We store something in a variable by using the set command as followed:
set VariableName "command1; command2; ..."

The only thing the code above does is store the commands in that variable. This means the commands are not yet executed. You execute them by calling the variable using the vstr command, which is done as followed:
vstr VariableName

Now all the commands in that variable will be executed.

You also bind the calling of a variable to a key:
bind x "vstr VariableName"

Important note: mind the caps in your variable name. Case sensitive!



Let's do an example. In the previous tutorial we discussed how to set your name. Let's try to do that by first storing it in a variable. I'm going to call that variable myName. Here goes:
set myName "name ^1*^4N^1oob^4Z^1or"
bind x "vstr myName"

So now my name will not be changed into *NoobZor until I press x. This construction might not make any sense at this point, cause this could have also been done by 1 line of code, not using the variable construction at all:
bind x "name ^1*^4N^1oob^4Z^1or"

This does exactly the same, but the variable construction is important for when we want to make a toggle, which is nothing more than a loop. In this loop we can rotate between multiple variables. The toggle will be explained in the eighth tutorial.

Back to the tutorial list