IRC Scripting Basics: Part 5
By Richard “GameGuru” Grant
Timers and Variables
For no particular reason, I’ve banded Timers and variables together in one tutorial.
mIRC allows you to create a limitless number of timers using the basic syntax:
/timer[name] [options] [time of activation] <repetitions> <interval> <command>
We can create a simple timer to echo “Hello” to our active mIRC window after 5 seconds by typing this in the editbox:
/timer 1 5 echo -a Hello
This will cause mIRC to create a new Timer (which it will call Timer1 (or TimerX where X is the next available free timer number)) which will perform the command specified once and after 5 seconds.
A simple use for a timer is shown below:
;This event puts the current time in the mIRC titlebar and updates it every second indefinitely
on *:START: {
.timer -com 0 1000 titlebar $!time
}
Quick rundown of the code, -com makes mIRC keep the timer accurate, forces it to run whether you are on a server or not, and lets you specify milliseconds instead of seconds respectively. The 0 means the timer will repeat indefinately every 1000 milliseconds (one second) and $!time means the titlebar will have the current time placed in it. You can see the difference between $!time and $time by removing it/adding it and restarting mIRC.
Variables allow you to store values of any type, you can even store dynamic values (like identifiers or other variables) and there are two types, local and global. Local variables are created using the /var command and are automatically removed when the script that uses them finishes whereas global variables created by typing /set remain even after the script that creates them ends and are removed using /unset. All variables in mIRC must be prefixed with a % but can have any name you like (and can even be created dynamically using variables and identifiers.)
Variables can also be created and be told to unset themselves after a specific amount of time, this is done by adding a -u<time> flag to the set command. This works much in the same way as creating a timer which performs the unset command on a variable.
;Example of usage of local and global variables
on ^*:TEXT:*:#wireplay: {
%text = $1-
set %name = $nick
var %numberofwords = $0
echo $chan $timestamp < $+ %name $+ > %text
echo $chan There were %numberofwords said in that line
}
alias displayinfo
{
echo -a last recorded line was: ” $+ %text $+ ” spoken by %name
}
%numberofwords could not be used in the displayinfo alias as it was only a local variable, if I attempted to display it $null would be returned, which would not be displayed in an echo.
If you want help with your mIRC scripting or have any questions in general about mIRC, please visit our IRC Help & Scripting Forum.