mIRC Home    About    Download    Register    News    Help

Print Thread
Checking for valid parameters #90695 16/07/04 03:14 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
How can I check if the parameter a user specifies is one of 3 valid parameters, without using multiple if-then-else statements? I think I need to use $regex, but not sure how to use $regex yet.

What I want to do:

Let's say I have an alias called "check", and "check" allows three different parameters to be specified. How can I check to see if the parameters a user specifies is one of the three valid parameters? I am trying to make this routine small as possible, that's why I prefer not to use multiple if-the-else statements to check the user input.

Re: Checking for valid parameters #90696 16/07/04 03:29 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
if ($istok(valid_parameter_1 valid_parameter_2 valid_parameter_3,$1,32)) { dostuff }

Change the parts in red


New username: hixxy
Re: Checking for valid parameters #90697 16/07/04 11:29 PM
Joined: Apr 2003
Posts: 701
K
Kelder Offline
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
if ($regex($1,/^(?:[color:green]param1|argument2|swich3)$/i)) { your code }[/color]

To find out more about regexes: search for regex tutorials here on the forum or on mirc scripting websites. It can take some time to learn completely, but it's worth it imho smile
The reference file is ofcourse http://www.pcre.org/pcre.txt but be prepared to skip a lot of useless stuff smile