mIRC Home    About    Download    Register    News    Help

Print Thread
required variables in aliases ($$1) error message #59619 09/11/03 12:54 PM
Joined: Jan 2003
Posts: 98
T
twigboy Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 98
(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

Re: required variables in aliases ($$1) error message #59620 09/11/03 01:03 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline
Vogon poet
Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
Of course!

Code:
 
blah {
if ($1) {
echo -a BLAH! $$1-
}
else {
echo -a * /blah: invalid parameters 
}
}
 

Re: required variables in aliases ($$1) error message #59621 09/11/03 01:07 PM
Joined: Jan 2003
Posts: 98
T
twigboy Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 98
i was hoping i didnt have to do it via coding
frown

Re: required variables in aliases ($$1) error message #59622 09/11/03 01:18 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: required variables in aliases ($$1) error message #59623 10/11/03 04:03 PM
Joined: Mar 2003
Posts: 27
Q
Quietust Offline
Ameglian cow
Offline
Ameglian cow
Q
Joined: Mar 2003
Posts: 27
Actually, even better would be to check if ($0 == 0) - otherwise, you could type "/blah $null hello" and it would fail.


* Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another
Re: required variables in aliases ($$1) error message #59624 10/11/03 06:28 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com