Would it be possible to have select case built in so it's more readable than several if-then-elseif- codes?
Been suggested numerous times, but I'll say it again, I'd love to see a switch statement implemented in mIRC.
So would I, There are alternatives to multiple if-then-else, but case statements is one of the things like FOR loops and arrays that I would love to see added just for the sake of elegance.
No real need:
test {
if ($istok(1.2.3,$1,46)) { goto $1 }
else { goto default }
:1
echo -a 1
goto endcase
:2
echo -a 2
goto endcase
:3
echo -a 3
goto endcase
:default
echo -a DEFAULT
:endcase
}
/test 1
/test 2
/test 3
/test ANYTHING ELSE.
Thats an ugly ugly hack. And honestly, I really wish people wouldn't even post things like this. It's obvious switch isn't needed, as the original poster said, if/else works just fine. We aren't saying "is there a way this can be done?" we are saying "here is a better way to do this, please implement it".
Using $istok like you have there won't work in all situations. Example:
test {
if ($istok(1.2.2.3.3.4,$1,46)) { goto $1 }
else { goto default }
:1.2
echo -a 1.2
goto endcase
:2.3
echo -a 2.3
goto endcase
:3.4
echo -a 3.4
goto endcase
:default
echo -a DEFAULT
:endcase
}
/test 1.2
DEFAULT
/test 2.3
DEFAULT
/test 3.4
DEFAULT
If that were in a switch() it wouldn't have gone to the default, it would have gone to the case for 1.2, 2.3, and 3.4
1. You could change the token C. Stupid point.
2. I was giving the guy an idea/suggestion, BLOW OFF.
Or even faster.
alias test {
var %a = $1
goto %a
:1
echo -a 1
return
:2
echo -a 2
return
:%a
echo Default
}
/test 1 ... 1
/test 2 ... 2
/test 3 ... Default
Labels, however, cannot contain spaces. If you have a label named "1", and another label named "1 2", doing a
/goto 1 2 will jump to the first one.