mIRC Homepage
Posted By: Poltergeist Switch statement - 05/04/03 05:02 PM
Maybe it would be usefull if mIRC's scripting language contained a switch statement as almost every language has. When you have to check a var against a lot of values, you have to use A LOT of if-else statements, which is very annoying. Switch statements would also make scripts more readable.
Posted By: theRat Re: Switch statement - 05/04/03 11:22 PM
just use elseif grin
Posted By: SaX0n Re: Switch statement - 06/04/03 01:07 AM
If you know that the label will exist, you can also use a GOTO jump as a fast and clean alternative to lots of IF statements.
Posted By: codemastr Re: Switch statement - 06/04/03 06:07 AM
Thats ugly and also doesn't support the 'default' case.
Posted By: qwerty Re: Switch statement - 06/04/03 04:45 PM
Either you forget too much or you're lying :tongue: We've discussed this in an older thread and it was shown that there IS a way to have a 'default' case:
Code:
  var %a = $1
  goto %a
  :1 | return One
  :2 | return Two
  :3 | return Three
  :%a | return Default
If the value of the variable is not among the text labels, mirc jumps to the special label named after the variable name itself. It may look a little weird and it's not documented anywhere but it works perfect.
Posted By: codemastr Re: Switch statement - 06/04/03 05:46 PM
yes but thats not really right. Meaning you can't

switch ($left($1,1)) {
case a:
echo -a it's an a
default:
echo -a it's not an a
}

You would have to assign the return value of $left to a variable, which makes it messy. Also it gets even more messy if you want to use something with spaces because instead of:

case "this is a test"

You need to
:this $+ is $+ a $+ test

But afaik, that doesn't even work, because mIRC doesn't evaluate an identifier in a label, so that would simply translate to ":this" which most likely, is not what the scripter would have intended.
Posted By: qwerty Re: Switch statement - 06/04/03 07:59 PM
I realise the limitations of the goto solution and I too would like a switch in mirc. I was just replying to your claim that you cannot have a 'default' case, grabbing the opportunity to inform the original poster of this feature (if he didn't know already).
© mIRC Discussion Forums