|
|
|
Joined: Aug 2007
Posts: 13
Pikka bird
|
OP
Pikka bird
Joined: Aug 2007
Posts: 13 |
I would like to see Switch and case being able to be embedded into the msl. Example: 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: 398
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Mar 2006
Posts: 398 |
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
Pikka bird
|
OP
Pikka bird
Joined: Aug 2007
Posts: 13 |
Thanks I might clean up the code later today
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
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:
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: 398
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Mar 2006
Posts: 398 |
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,033
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,033 |
I like it.
~ Edit ~ genius_at_work's example sold me on it.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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: 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: 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
Pikka bird
|
Pikka bird
Joined: Nov 2007
Posts: 19 |
You could probably do something like:
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: 398
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Mar 2006
Posts: 398 |
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
Fjord artisan
|
Fjord artisan
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
Pikka bird
|
Pikka bird
Joined: Nov 2007
Posts: 19 |
Oh. A simple $replace($1-,$chr(32),_) would do the trick
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
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
Pikka bird
|
Pikka bird
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: 398
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Mar 2006
Posts: 398 |
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
For the sake of simplicity I'd rather have || support. switch ($moo) {
case (1 || 2) { echo -a $moo is 1 or 2 }
}
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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
Pikka bird
|
OP
Pikka bird
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
Hoopy frood
|
Hoopy frood
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
Hoopy frood
|
Hoopy frood
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
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
Hoopy frood
|
Hoopy frood
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 for "X: says"
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
|
|
|
|