mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#195336 22/02/08 08:25 AM
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
I would like to see Switch and case being able to be embedded into the msl.
Example:
Code:
on *:TEXT:*:*:{
  switch ($1-) { 
    Case help me:
      msg $nick I have no desire to help you in the channel, or in a pm.
    case free stuff:
      msg $nick I WANT SOME!!!
    default:
      echo -t $iif($chan,$chan $+(>,$nick,<) $1-,$nick $+(>,$nick,<) $1-
  }
}

It would end a whole huge block of if, elseif, elseif, elseif, and else.
Because I find myself and many others with code that ends up doing that, I find that aliases aren't any better in those situations... unless I have a timer and need to do multiple things on it.

But even if the code above is innacurate, it gets to the point.

Any comments/suggestions are appreciated. No spam, negative feedback (unless it is constructive criticism) is allowed. No swearing, or use of any provocative language is allowed either. Please don't flame any user on this thread because they are trying to help.

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
I second that. Seems like a good idea and I cant see any problems with it.

TBH, I thought this was allready somewhere... but can't find it.


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
Thanks laugh
I might clean up the code later today

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I think it would be useful to have this structure in mIRC. Though I think it needs to be a more mIRC-style structure. Example:

Code:

switch (%var) {
  case (help me) {
    ;action 1 for case 'help me'
    ;action 2 for case 'help me'
  }
  case (something) ;action 1 for case 'something'
  case (%text) {
    ;actions for case %text
  }
  default {
    ;actions for default case
  }
}



Notice the similar structure to if/else/while statements, using { } for multiple statements, and allowing a single statement without { }.

-genius_at_work

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
So does anyone object? This sounds like one of those useful additions that would only make mIRC greater.


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

I like it.

~ Edit ~
genius_at_work's example sold me on it.


Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
While that may look more like other mIRC scripting statements that take a code block, I think the use of ":" is a more suitable syntax. The primary reason is to show that the code following each case does not behave the same as a code block, ie. each case is not self-contained, but rather they cascade into one another.

Just to make it clear to anyone who might not know how switch/case statements (should) behave:
Code:
switch ($moo) {
  case 1:
    echo -a moo 1
  case 2:
    echo -a moo 2
    break
  case 3:
    echo -a moo 3
}


If $moo equals 1, that code would output the following:
Code:
moo 1
moo 2

Once a switch statement finds a case that matches, it executes all case statements following that one aswell until it reaches a break. The use of ":" rather than braces is a better indicator of that I think. Presumably this is also why other programming languages use the same structure.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Nov 2007
Posts: 19
J
Pikka bird
Offline
Pikka bird
J
Joined: Nov 2007
Posts: 19
You could probably do something like:
Code:
on *:TEXT:*:*:{
  goto $1-
  :help me
    msg $nick I have no desire to help you in the channel, or in a pm.
  :free stuff
      msg $nick I WANT SOME!!!
  :error
    echo -t $iif($chan,$chan $+(>,$nick,<) $1-,$nick $+(>,$nick,<) $1-
}


But a proper switch statement in mIRC would be nice too

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
I never though of that - Nice idea... Still would like to see case switching though


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
doesn't work as expected unfortunately! those tags can't contain spaces, second word onwards is ignored



"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Nov 2007
Posts: 19
J
Pikka bird
Offline
Pikka bird
J
Joined: Nov 2007
Posts: 19
Oh. A simple $replace($1-,$chr(32),_) would do the trick grin

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
a switch case would be brilliant but im with starbucks_maffia, mIRC should not deviate from the standard switch/case syntax.

switch/case,for,foreach still high on my wishlist!


$maybe
Joined: Nov 2007
Posts: 19
J
Pikka bird
Offline
Pikka bird
J
Joined: Nov 2007
Posts: 19
And I just noticed you also need a halt or something to stop the next goto loop

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
or a Goto end lol


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
For the sake of simplicity I'd rather have || support.

Code:
switch ($moo) {
  case (1 || 2) { echo -a $moo is 1 or 2 }
}

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
But then that wouldn't do the same thing. You couldn't emulate my example of echoing "moo 1[color:red]\nmoo 2[/color]" if $moo was 1, and just "moo 2" if $moo was 2. If every case is completely self-contained from the ones following it then switch/case is really no more effective than using if/elseif/else.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
Thanks for posting, I have seen many flaws in the way I said it.
Thanks for posting good feedback, I like to hear from people who share the same ideas and have differences that can be solved/optimized. But yet I am still young, I would like to learn now that way I can start planning for the future!

So other then that, I think this would make a nice addition to the already polished, and great performing syntax of mSL.

One question though:
If you were to rate this suggestion, would it be good? OK? too buggy and should be taken off? or so off topic that this needs to be reconsidered and removed/re-evaluated?

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You could do that with an if statement.

I'm not against the functionality you're proposing only the syntax. Every other construct has { } code blocks, this should follow suit.

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Is case needed? no, as you said if blocks can achieve the same. however semantically they provide a huge improvement, and for that matter you have to wonder why other "curly" languages choose for a
Code:
switch(){
   case:
   default:
}

construct to begin with instead of wanting to enforce a different approach "because it's more mIRCish".


$maybe
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
you need to choose an "mircish" approach because the syntax has to be compatible, otherwise you completely destroy the parser...

for instance "case:" is a valid command name and so is "default:", so how would the parser differentiate?

case N: might work but again, mIRC has no concept of strings, so you could easily end up with

Code:
case X: says: 
   blah


for "X: says"


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Page 1 of 2 1 2

Link Copied to Clipboard