Switch Statement in msl

By sunslayer on Feb 28, 2011

well someone thought that it was impossible to have a switch-like statement in mIRC, so i figured I'd give it a try

alias switch {
  var %condition = $1,%1 = $$2-,%def = $true
  if (!$regex(switch,%1,/(?:case\W([^ ]+)|(default))\x3A\W(.+?)break/Sig)) { echo -a Syntax error! | halt }
  var %x = $regml(switch,0),%c = 1
  while (%c <= %x) {
    if ((%condition == $regml(switch,%c)) || (%def && $regml(switch,%c) == default)) {
      var %def = $false,%reg = $regml(switch,$calc(%c +1)),%xx = $numtok(%reg,124),%xxx = 1
      while (%xxx <= %xx) {
        inc %xxx
    inc %c 2


Sign in to comment.
bone282   -  Mar 11, 2011

looks like someone has already made it.


its a great looking script btw, nice compact use of COM too.

bone282   -  Mar 07, 2011

i think it has many practical uses. many site offer a JSON web service
even google offers a multitude:
web search
to name a few
And as for parsing, you could use a COM call to MSScriptControl.ScriptControl
but anyway, it seems im alone in thinking there is a practical use for this in mirc. ah well

sunslayer   -  Mar 02, 2011

thanks bone282, but i can't really see a practical application for JSON in mIRC and would be quite messy, syntactically, to generate and parse for a typeless language
on another note though, i did post a OOP style structure a little while ago if your interested

bone282   -  Mar 02, 2011

i dont use mIRC anymore. but, having a switch alias not too dissimilar in its use from the switch() function found in many languages. i like it. +rate +like.

love to see a json_decode alias next though ;]

jaytea   -  Mar 01, 2011

it's a good idea, but unfortunately the syntax required is awkward and imposes too many annoyances on the user such as:

  • the inability to use certain phrases in their commands (such as 'break')
  • the obvious drawback of having to escape command separators and remembering to add '$&' to the end of each line
  • the fact that the entire switch statement spans one single command and is therefore constrained by mIRC's line length limit of 4,150 characters (even, and often more significantly, AFTER evaluation).
  • similarly, the entire switch statement is evaluated at once, resulting in unnecessary and possibly undesired evaluation of pieces of code. some of these may be computationally expensive and some may produce unwanted side effects.

while it is possible to implement this with less awkward syntax and improve upon it by trimming this list of annoyances, we cannot escape the fact that, in mIRC, /goto provides the most simple and efficient switch statement analogy ;P however, like that 'arrays in mIRC' demonstration from a while back, this serves as a fun and thought provoking demonstration

sunslayer   -  Feb 28, 2011

it was a blatantly obvious solution, ([^ ]+)

Jethro   -  Feb 28, 2011


sunslayer   -  Feb 28, 2011

@Gummo nice catch, but there doesn't seem to be a quick fix for it

Gummo   -  Feb 28, 2011

Jethro_, probably referring to the fact that you have to join each line together to form a pseudo-switch which is actually just a single command.

Gummo   -  Feb 28, 2011

Won't that fail if you use any non-word character as your case criteria? (\w+)

Jethro   -  Feb 28, 2011

What does it mean by "switch like?"

sunslayer   -  Feb 28, 2011

here's an example alias:

alias tests {
  switch $1 $&
    case 1: $&
    echo -a Hello $!+ $!chr(124) $chr(124) echo -a World! $&
    break $&
    case 2: $&
    echo -a Hello World! $&
    break $&
    case 3: $&
    echo -a $me $&
    break $&
    default: $&
    echo -a Default case $&
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.