mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#155359 06/08/06 12:34 AM
Joined: Aug 2006
Posts: 7
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Joined: Aug 2006
Posts: 7
have switch..case in mirc??

i hope to see it on the next version. wink

#155360 06/08/06 01:11 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Clarification would be helpful. Also if this is a suggestion for a future version, then it should be in the Suggested Features forum, not Connection Issues

#155361 06/08/06 02:23 AM
Joined: Aug 2006
Posts: 7
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Joined: Aug 2006
Posts: 7
i'm sorry confused

#155362 06/08/06 09:49 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
A switch/case statement in mIRC syntax would be like this (if it followed C):

Code:
switch ($time(HH:nn)) {
  case (10:00) {
    ; $time(HH:nn) is 10:00
    break
  }
  case (11:00) {
    ; $time(HH:nn) is 11:00
    break
  }
  default {
    ; $time(HH:nn) is neither of the above
  }
  ; Here is where the script will go to when mIRC hits a break statement. 
  ; Without the break statements mIRC would just fall through to the next case.
}

#155363 06/08/06 12:43 PM
Joined: Aug 2006
Posts: 7
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Joined: Aug 2006
Posts: 7
thank a lot

#155364 06/08/06 12:53 PM
Joined: Aug 2006
Posts: 7
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Joined: Aug 2006
Posts: 7
ON *:JOIN:*:{
switch ($time(HH:nn)) {
case (19:50) {
echo -a 4 $time(HH:nn) is 19:50
break
}
case (19:51) {
echo -a 7 $time(HH:nn) is 19:51
break
}
default {
echo -a $time(HH:nn)
}
}
}

output:
SWITCH Unknown command
-
CASE Unknown command
-
CASE Unknown command
-
DEFAULT Unknown command
confused

#155365 06/08/06 05:22 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
From Hixxy's post:
Quote:
if it followed C

#155366 06/08/06 05:56 PM
Joined: Aug 2006
Posts: 7
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Joined: Aug 2006
Posts: 7
ohhh i see blush

#155367 06/08/06 06:54 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If you would clarify just what switch case does, as I'm unfamiliar with the term from a programming perspective, something might be coded, however, until I know just what it's supposed to do, I can't even start thinking about it, realistically.

#155368 06/08/06 07:00 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I explained it above. Read the comments.

#155369 06/08/06 07:34 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741

#155370 11/08/06 10:15 AM
Joined: Oct 2004
Posts: 73
M
Babel fish
Offline
Babel fish
M
Joined: Oct 2004
Posts: 73
Here's a pseudo switch thingy for giving time on join. Note: it's untested and I probably wouldn't suggest coding this way:
Code:
 ON ^*:JOIN:*:echo $color(info) $chan $nick joined $chan at $switch($time(h:n:tt)) | haltdef
alias switch {
  tokenize 58 $1
  goto $iif((($2) && ($isid) && ($1 isnum 1-12) && ($2 isnum 0-59)),$iif($istok(0 15 30 45,$2,32),$2,$iif($2 < 30,past,to)),error)
  :0
  return exactly $1 o'clock $3
  :15
  return a quarter past $1 $3
  :30 
  return half past $1 $3
  :past 
  return $2 $iif($2 == 1,minute,minutes) past $1 $3
  :45 
  return a quarter to $iif($1 == 12,1 $3,$calc($1 + 1) $iif($3,$iif($1 == 11,$iif($3 == am,pm,am),$3)))
  :to 
  return $calc(60 - $2) $iif($2 == 59,minute,minutes) to $iif($1 == 12,1 $3,$calc($1 + 1) $iif($3,$iif($1 == 11,$iif($3 == am,pm,am),$3)))
  :error 
  echo $color(wallops) -a SWITCH statement called incorrectly
} 

Edit: correcting typo's caused double-spacing

Last edited by Mardeg; 11/08/06 11:24 AM.
#155371 14/08/06 01:52 AM
Joined: Mar 2004
Posts: 210
F
Fjord artisan
Offline
Fjord artisan
F
Joined: Mar 2004
Posts: 210
Quote:
I probably wouldn't suggest coding this way:
While it propably won't do what SWITCH does in most languages (run a lot faster than a nested If-ElseIf-End If) it's a lot easier to read. Nice coding.

#155372 14/08/06 03:21 PM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Quote:
Quote:
I probably wouldn't suggest coding this way:
While it propably won't do what SWITCH does in most languages (run a lot faster than a nested If-ElseIf-End If) it's a lot easier to read. Nice coding.


While in C (or other compiled language with switch), there are a couple advantages to using switch, it is not as likely possible to use a switch in mIRC and get those advantages since it is a scripting language. The only point of adding is would be "for looks".

BTW, I wouldn't say "runs a lot faster" above, I'd say it "run somewhat faster (only for compiled languages)". smile

You could also script this to some point... wink
Code:
alias switch { set %~SwitchEval $1 | return $null }
alias case { return $iif($1 == %~SwitchEval, $true, $false) }
alias case-switch-test {
  var %Test 1
  $switch(%Test) {
    if ($case(1)) { echo -s Testing 1 }
    if ($case(2)) { echo -s Testing 2 }
  }
}


NaquadaBomb
www.mirc-dll.com
#155373 14/08/06 05:27 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A switch case would run considerably faster in mIRC script than if/else's because it would evaluate the condition only once, compared to evaluating it up to n times and an additional variable being evaluated n-1 times aswell using the most efficient if/else equivalent (where n is the number of cases). The goto method can just about match the efficiency of a switch statement for simple situations but it is deeply flawed and can cause major issues if you intend to use error handling (not to mention it allows only a single "switch-equivalent" in each scope).

Your example code doesn't allow for cascading which is a defining feature of switch statements.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#155374 15/08/06 12:00 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
This is just the same arguement we all went over ages ago.

Sure it would be nice, might even pick up speed a bit, but really, is it needed to make the mirc scripting language workable?

#155375 15/08/06 07:16 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Sure it's not needed to make it workable, but as I'm sure was pointed out previously also, 90% of the scripting language isn't needed. While loops exist despite being fully emulatable by goto's but they're in the language because they provide greater readability and save the need to use goto (which can often be misused). The same reasoning applies to switch/case statements - arguably even more so since the goto workaround is more complex and error-prone than the goto equivalent of a while loop.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#155376 15/08/06 10:24 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Still its the same thing discussed maybe 6 months ago now isnt it.

#155377 16/08/06 12:29 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
There's nothing in the thread that was linked to properly showing the (potential) efficiency bonuses of a switch/case statement or the full issues with using goto. All that thread really says is "switch/case would be nice but it's not needed", which is true but not the whole story. Of course there are even older threads about this, but seeing as people very rarely search that far back there's no harm summing it up again.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#155378 17/08/06 01:42 AM
Joined: Jun 2003
Posts: 12
Y
Yil Offline
Pikka bird
Offline
Pikka bird
Y
Joined: Jun 2003
Posts: 12
The speed benefits of using goto can be VERY good. In a dialog callback that would often involve a lot of IF statements it can literally be an ORDER OF MAGNITUDE faster.

mIRC has no intermediate compiled form for aliases and thus must parse each call to an alias on the fly. This is quite slow... I'm guessing that because the parser doesn't have to actually evaluate anything until it finds the :LABEL it just sorta scans along keeping track of {}'s and ()'s and stuff.

To prove this a simple benchmark:

ticks for 10000 iterations:
calling empty alias: 438
calling 10 failed empty if statements in a row: 1719
calling 10 failed empty if statements one inside the other: 1766
calling alias with 10 if statements but a goto 10th at the start: 1047

Conclusion: the mIRC parse is clearly doing something differently with the goto statement. 10 if statements with one inside the other SHOULD mean that only the first is evaluated and the others skipped over, but based on the timing above this isn't happening and it's fully parsing everything but just not evaluating it. The goto on the other hand is somehow skipping over stuff quickly looking for the :TAG but yet still obeying {}'s.

Anyway, goto's are definitely faster than IFs provided you can skip executing/parsing a lot of code in the alias such as in dialogs callbacks...

Page 1 of 2 1 2

Link Copied to Clipboard