Using $isid

Contributed by dohcan
This mini-tutorial assumes knowledge of creating custom aliases. This is not intended to teach you how to script, only to show you a technique.

Ever wondered if you can create aliases and identifiers that share the same name, like the /nick command used for changing your own nick and the remote $nick identifier that returns the nickname of the person who triggered the the action?
Check for $isid
Before mIRC v5.6, this really wasn't practical, but one of the new additions of of 5.6 was the identifier $isid, which applies to custom aliases. With the identifier, you can tell if the alias was called using /aliasname or $aliasname. If it was used as a command, $isid returns false. If it was used as an identifier, $isid returns true.

I would say this is more of a vanity feature. You could always get by and simply name your aliases and identifiers different names, and never have any conflicts. With $isid, however, you could write some code that is a bit cleaner. For one of the addons I created, I was regularly reading and writing to an .ini file. I had created the aliases:
alias c.set {
  if ($len($1)) && ($len($2)) && ($len($3)) writeini settings.ini $1 $2 $3-
  else echo -a * c.set: invalid syntax
}
alias c.get {
  if ($len($1)) && ($len($2)) return $readini settings.ini $1 $2
  else echo -a * $!c.get: invalid parameters
}
Then I would use them in the form of:
/c.set <section> <key> <value>
$c.get(section, key)
Using $isid, this could be rewritten as one alias called c.set:
alias c.set {
  if ($isid) {
    if ($len($1)) && ($len($2)) return $readini settings.ini $1 $2
    else echo -a * $!c.set: invalid parameters
  }
  else {
    if ($len($1)) && ($len($2)) && ($len($3)) writeini settings.ini $1 $2 $3-
    else echo -a * c.set: invalid syntax
  }
}
And now I would use:
$c.set(section, key)
/c.set <section> <key> <value>
If we had several instances where we could use this, we could simply devote an alias for each section that is needed, and not have to bother remembering all of the different alias names.

On a side note, if you are using this technique for something that is very cpu-intensive, it would probably be best to not use $isid, but for most cases, I think the performance hit would be negligible.
All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.