mIRC Homepage
(aliases)
blah {
echo -a BLAH! $$1-
}


when called
/blah asd qwe zxc
it'll echo "BLAH! asd qwe zxc"

but when you type
/blah
nothing will happen, since $1 isnt specified.

is it possible to add a custom message, similar to the default mIRC error messages?
eg.

* Too few parameters: $blah

or

* * /blah: invalid parameters
Of course!

Code:
 
blah {
if ($1) {
echo -a BLAH! $$1-
}
else {
echo -a * /blah: invalid parameters 
}
}
 
i was hoping i didnt have to do it via coding
frown
Code:
blah {
  if ($1 == $null) echo -sec Info * /blah: insufficient parameters
  else echo -a BLAH! $1-
}


You might also want to check the identifier $isid to see if the command was called as an identifier ($blah(parameter1, parameter2, ...)) and change your response accordingly - ie. you wouldn't want to give an error message for /blah if it was called as $blah().

Also, it's important to use if ($1 == $null) to check for the presence of a parameter and NOT use if (!$1) since that will check that the parameter has a boolean false value, which could mean the parameter doesn't exist or is a 0 (so /blah 0 would return an error if you used that).
Actually, even better would be to check if ($0 == 0) - otherwise, you could type "/blah $null hello" and it would fail.
Actually it wouldn't fail in any case.

1) If one typed /blah $null hello (ie with one slash), $1 would be filled with the string "$null". In this case, if ($1 == $null) would be FALSE; if ($1 == $[color:red]!null)[/color] would be TRUE.

2) If //blah $null hello is issued (double slash), $1 wouldn't be $null; it would be "hello". In /commands, the tokenizing is done just like in token identifiers: null tokens are simply ignored and any leading/trailing token separators are stripped off. This also happens with null tokens in the middle of the string and is the root of the infamous "mirc kills multiple spaces" problem. Null tokens are permitted/preserved only in custom identifiers: $blah($null,hello) would fill $1 with $null and $2 with "hello".

Speaking of $0 though, I like your approach more because it's faster: $null has to be evaluated, 0 hasn't. Moreover, if you use (!$0) instead of ($0 == 0) (the latter isn't necessary since $0 will always be a number), it's even faster.
© mIRC Discussion Forums