mIRC Home    About    Download    Register    News    Help

Print Thread
#18170 05/04/03 05:02 PM
Joined: Apr 2003
Posts: 26
P
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Apr 2003
Posts: 26
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.

#18171 05/04/03 11:22 PM
Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
just use elseif grin

Last edited by ParaBrat; 05/04/03 11:29 PM.

Code:
//if ( khaled isgod ) echo yes | else echo no
#18172 06/04/03 01:07 AM
Joined: Feb 2003
Posts: 32
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Feb 2003
Posts: 32
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.

#18173 06/04/03 06:07 AM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Thats ugly and also doesn't support the 'default' case.

#18174 06/04/03 04:45 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#18175 06/04/03 05:46 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

#18176 06/04/03 07:59 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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).


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

Link Copied to Clipboard