|
|
|
Introduction to Variables
Variables are very similar to aliases. The important difference between aliases and variables is that aliases are only expanded when at the beginning of a command, while variables are expanded anywhere. To expand the variable, you precede its name with the @ character. Note that this is different then TINTIN where variables start with a $.
To define a variable, you use the #VARIABLE command. For example, #VAR container waterskin stores the string 'waterskin' into the variable container. To return the contents of the variable, precede its name with the @ character. For example, fill @container would expand to fill waterskin.
Another assignment syntax is also provided. As with some programming languages, you can use the syntax variable=value to assign a value to a variable.
To illustrate the use of variables, with the variable @container defined as shown above, you can now create an alias #ALIAS fs {fill @container statue}. Now when you enter fs on the command line, the current value of the container variable (waterskin from the above example) is expanded and the command fill waterskin statue is sent to the MUD.
Variables are expanded in the command line too. If you enter fill @container on the command line, it would send fill waterskin to the MUD.
You can edit your variables like this on the command line, or you can use the Package Editor Variables screen.
zMUD Users: In CMUD, the value assigned to a variable is automatically evaluated as an expression. zMUD only expanded the value and didn't evaluate it. For example, if @a has the value of 1, then b=@a+1 will assign 2 to @b in CMUD as expected. In zMUD it would have assigned "1+1" to @b, which was confusing for many people. Also, in CMUD, variables are always expanded in the command line. There isn't any Expand Vars preference option.
Local Variables
Local variables always start with a $ character instead of a @. A Local variable is temporary and only exists during the execution of the script. However, local variables are much faster than using normal variables. You only use local variables within a script, not from the command line. See the Local Variables topic for more information on this advanced topic.
System Variables
CMUD has some pre-defined variables that are maintained automatically by the system. These pre-defined variables start with a % character instead of @. They are very similar to functions (which also start with %) except that the system variables do not take any arguments and never have parenthesis after them. For example, the %char system-variable contains your character name (as entered in the Edit Session screen for your session icon). This is very different than the %char function which returns an ascii character value. |
|