mIRC Homepage
Posted By: Cyrex Checking for valid parameters - 16/07/04 03:14 PM
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.
Posted By: tidy_trax Re: Checking for valid parameters - 16/07/04 03:29 PM
if ($istok(valid_parameter_1 valid_parameter_2 valid_parameter_3,$1,32)) { dostuff }

Change the parts in red
Posted By: Kelder Re: Checking for valid parameters - 16/07/04 11:29 PM
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
© mIRC Discussion Forums