Variables

 

Variables are temporary storage areas to which you can assign values which you can use later in your scripts.

 

If a variable is referred to and it does not exist, it returns the value $null. The $null value can be used in comparisons in if-then-else statements to control branching etc.

 

The following commands allow you to create and set the values of variables.

 

/set [-snzeglkipuN] <%var> [value]

This sets the value of %var to the specified value.

 

If you specify the -uN switch, %var is unset after N seconds, assuming it is not set again by another script. If you specify a zero for N, the variable is unset when the script finishes.

 

The -g switch sets a global variable. Normally, if a local variable already exists, it takes precedence, so this switch allows you to override that.

 

The -k switch keeps the current -uN setting for a variable.

The -n switch prevents mathematical operations.

The -z switch decreases %var until it reaches zero and then unsets it.

The -e switch unsets the variable when mIRC exits.

The -l switch makes the variable a local variable.

The -i switch initializes a variable only if it does not already exist.

The -p switch treats value as literal text, including quotes and spaces.

 

/unset [-sgl] <%var>

This unsets and removes the specified variables from the variables list. If you specify a variable with wildcard characters then all matching variables will be removed.

 

The -gl switches unset a global or local variable respectively.

 

/unset %test*

 

This will remove all variables beginning with the word %test.

 

You can also set/unset dynamic variables using [] brackets:

 

vartest  {

 set %a [ $+ b ] 1

 set %a [ $+ c ] 2

 set %a [ $+ d ] 3

 

 echo ab = %ab

 echo ac = %ac

 echo ad = %ad

 

 unset %a [ $+ b ] %a [ $+ c ] %a [ $+ d ]

}

 

/unsetall

This unsets and removes all variables from the variables list.

 

/inc [-cszeuN] <%var> [value]

This increases the value of %var by value.

 

If you specify the -uN switch, %var is increased by the value once and then %var is unset N seconds later, assuming it is not set again by another script.

 

The -c switch increases %var once per second.

The -z switch decreases %var until it reaches zero and then unsets it.

The -e switch unsets the variable when mIRC exits.

 

/dec [-cszeuN] <%var> [value]

This decreases the value of %var by value.

 

If you specify the -uN switch, %var is decreased by the value once and then %var is unset N seconds later, assuming it is not set again by another script.

 

The -c switch decreases %var once per second.

The -z switch decreases %var until it reaches zero and then unsets it.

The -e switch unsets the variable when mIRC exits.

 

Assigning values

The equal sign can be used to assign values to variables:

 

%i = 5

%xyzi = 3.14159

%count = $1

%text = how now brown cow?

 

Mathematical operations

The following operations can be performed when using the equal sign:

 

%x = 5 + 1

%x = 5 - %y

%x = %x * 2

%x = %z / $2

%x = $1 % 3

%x = 2 ^ %w

 

Only a single operation can be performed in an assignment.

 

Note: operations are performed on the final contents of the value being assigned. This means that the -n switch, with /set or /var, will need to be used, as in the following example, to prevent a double evaluation.

 

If %y is the literal text 1 + 2:

 

set %x %y

echo x: %x is equal to 3

 

set -n %x %y

echo x: %x is equal to 1 + 2

 

You can also use the $calc() identifier which allows you to perform complex calculations.

 

//echo 1 $calc(3.14159 * (2 ^ %x % 3) - ($ticks / (10000 + 1)))

 

For floating point numbers you can also use the $round(N,D) and $int(N) identifiers to handle precision of the decimal digits. The number of decimals is currently limited to 5 digits.

 

Local Variables

Local variables are variables that exist only for the duration of the script in which they are created and can only be accessed from within that script. They can be created with the /var command:

 

/var %x

 

This creates the local variable %x in the current routine and can only be referenced from inside this routine.

 

/var %x = hello

 

This creates a local variable %x and assigns it the value hello.

 

You can create multiple local variables by separating them with commas:

 

/var %x = hello, %y, %z = $me

 

loop {

 var %x = 1

 :next

 echo item %x

 inc %x

 if (%x < 10) goto next

}

 

Note: This uses the same switches as the /set command.

 

Identifiers

 

$var(%var,N)

Returns the Nth matching variable name.

 

Properties: value, local, secs

 

You can use a wildcard in the variable name.

 

If N = 0, returns total number of matching variable names.

 

Note: This searches both local and global variables.

 

Big Float

 

If a script needs to perform calculations with very large numbers, it can enable big float support either for a specific command or for the whole script using the following methods:

 

To enable big float for a command, use a variable with a .bf extension, such as %var.bf. When used in a command/identifier, this enables big float calculations for that command/identifier.

 

To enable big float for the whole script, use the /bigfloat [on|off] command. This will affect all calculations in commands and identifiers until the script exits.

 

A script can check if big float is currently enabled by using the $bigfloat identifier.

 

Note: Big float calculations are much slower than normal calculations, so should only be used when necessary.