VARIABLE
Command: #variable {variable name} {text to fill variable}
Variables differ from the %0-99 arguments in the fact that you can
specify a full word as a variable, and they stay in memory for the
full session unless they are changed. They can be saved in the
coms file, and can be set to different values if you have two or
more sessions running at the same time. Variables are global for
each session and can be accessed by adding a $ before the variable
name.
Example: #alias {target} {#var target %0}
#alias {x} {kick $target}
The name of a variable must exist of only letters, numbers and
underscores in order to be substituted. If you do not meet these
requirements do not panic, simply encapsulate the variable in braces:
Example: #variable {cool website} {http://tintin.sourceforge.net}
#chat I was on ${cool website} yesterday!.
Variables can be escaped by adding additional $ signs.
Example: #var test 42;#showme $$test
Variables can be nested using brackets:
Example: #var hp[self] 34;#var hp[target] 46
You can see the first nest of a variable using $variable[+1] and the
last nest using $variable[-1]. Using $variable[-2] will report the
second last variable, and so on. To show all indices use *variable[].
To show all values use $variable[]. To show all values from index 2
through 4 use $variable[+2..4].
Nested variables are also known as tables, table generally being used
to refer to several variables nested within one specific variable.
It's possible to use regular expressions.
Example: #show {Targets starting with the letter A: $targets[A%*]
To disable using regular expressions start the match with '='.
Example: #show {A target literally defined as A%*: $targets[=A%*]
To see the internal index of a variable use &<variable name>. To see
the size of a table you would use: &targets[] or &targets[%*]. A non
existent nested variable will report itself as 0.
Example: #show {Number of targets starting with A: &targets[A%*]
In some scripts you need to know the name of a nested variable. This
is also known as the key, and you can get it using *variable. For
example *target[+1]. To get the first variable's name use *{+1}.
It's also possible to declare a table using brace notation. Using
#var hp[self] 34 is the equivalent of #var {hp} {{self}{34}}. This
also allows merging tables. #var hp[self] 34;#var hp[target] 46 is
the equivalent of #var {hp} {{self}{34} {target}{46}} as well as
#var {hp} {{self}{34}} {{target}{46}} or if you want to get creative
the equivalent of #var hp[self] 34;#var {hp} {$hp} {{target}{46}}.
Comment: You can remove a variable with the #unvariable command.
Related: cat, format, function, local, math, replace and script.
|