Introduction
You might have seen lots of scripts already, and in some scripts,
you notice that there are weird identifiers and no matter what you
do, those identifiers cannot be found in the mIRC.hlp or the
versions.txt! Chances are, you have stumbled upon a custom identifier.
This tutorial will attempt to introduce to the scripter what a custom
identifier is, and how to write them and how useful they can be.
What is a custom identifier?
A custom identifier is simply an identifier that the scripter himself or herself
created. It simply means that we can make our own identifiers different from what
mIRC itself offers.
Writing your own identifiers
Custom identifiers are simply aliases. The difference is that it returns a value
and it uses the /return command (the /return command has more than one use, see
for instance the article on writing better addons for more explanation).
Since it is easier to explain by giving an example, here is an example alias or
custom identifier:
UIN /return 31337
What you have just created is an identifier which is $UIN and returns the value
of 31337.
So the next time someone asks your ICQ number, you will have a ready identifier to use.
You can stick that in your own aliases, for example:
info /say My ICQ number is $UIN
A custom identifier can be a single line or multiple lines, it can be simple or can
be as complicated as you like. Here is another example of a custom identifier, slightly
advanced that the one above as it accepts parameters:
add /return $calc($1 + $2)
The above can be used in the following:
sum /echo -a The sum of 1 and 2 is $add(1,2)
And here is the same $add identifier, even more complicated as it accepts more than
two parameters:
add {
var %sum = $calc($1 + $2)
if ($3) $calc(%sum = %sum + $3)
return %sum
}
What it does is simply allow you to have a 3rd parameter so you can add three numbers.
Why write custom identifiers?
Similarly with normal identifiers, custom identifiers allow you to save time and space.
Time, because you do not need to type repetitive coding, and space because you cut down
the number of letters, symbol, or characters you have to type. It's just like having
aliases that cut down repetition (see the module tutorial by Ntd) but with slightly
different function.
For example, the $atime identifier. Lots of scripters use $atime to display the time
in non-military format. Instead of having to use $time(hh:nntt) in different places
of your script, you will only need to place the following in your aliases, and voila,
you already have a $atime that does the same thing as $time(hh:nntt).
atime return $time(hh:nntt)
And this alias will save you a lot of time and effort. Just imagine if you have to do
something bigger.
Fun things
Custom identifiers are cool. Why? Because you can make them act like real identifiers.
For example:
sub {
if (($1 isnum) && ($2 isnum)) return $calc($1 - $2)
elseif (($1 == $null) || ($2 == $null)) {
echo $colour(info) -s * $!sub: insufficient parameters.
linesep -s
halt
}
elseif (($1 !isnum) || ($2 !isnum)) {
echo $colour(info) -s * $!sub: invalid parameters.
linesep -s
halt
}
}
As you can see, the above identifier checks if the two parameters provided are numbers
and it also checks if there are two numbers given. If the parameters (or the $1 and $2)
given are not numbers, or are not given at all, the $sub will give an error message
and will halt the script that is using it.
Speaking of which, you can use a custom identifier to halt an executing script if it
encounters an error, or you can make it continue. For the above example, the /halt
command will halt the execution of a script if it encounters an error due to a wrong
usage of the $sub() identifier. If, however, the /halt is changed to a /return, a value
of $null will be returned but the script that is calling it will continue to process.
As I have mentioned earlier, custom identifiers work like real identifiers. You can also
use $result with it. For example:
test {
tokenize 32 $1-
sub $1 $2
echo -a The result is $iif($result > 0,greater,less) than zero
}
This is just a very simple example from which you can grab ideas from.
Hints and Tips
Custom identifiers have to have a /return command at the end of the alias. It does not
need to return a value. If you simply put a /return at the end, it will return a $null
value.
Custom identifiers cannot have the same names as built-in identifiers. If you have an
identifier which has exactly the same name as an mIRC identifier, the mIRC identifier
will override your own and will ignore your custom identifier.