|
Joined: Mar 2006
Posts: 392
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 392 |
is there anything like "select case"/"switch"? eg: case $1 {
:001 return we got 001
:002 echo -a Something else
:default echo -a Default case
} at the moment im using something like that, but with Goto... eg
goto $1
:001
{ return we got 001 | goto break }
:002
{ echo -a Something else | goto break }
:break
(no default) Is there a cleaner way to do this?
Last edited by The_JD; 21/07/08 11:39 AM.
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
WhipLash
|
WhipLash
|
Im gonna ask the really dumb question: What case are we talking about? Cause 001 is ascii for some special character, and 002 is the ascii for bold. As for case: $islower(text) Returns $true if text is all lower case.
$isupper(text) Returns $true if text is all upper case.
But somehow i think mean the control codes..
|
|
|
|
Joined: Mar 2006
Posts: 392
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 392 |
Lol Sorry I mean a function that is similar to PHP's switch function... See http://au2.php.net/switch
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
WhipLash
|
WhipLash
|
Ah.... While i prsonally cant answer this, but i'd also like to know.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
There is presently no CASE structure in mIRC, though it has been requested many times.
I've seen it simulated with goto and labels.
-genius_at_work
|
|
|
|
Joined: Mar 2006
Posts: 392
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 392 |
So I guess the way I'm doing it is the way to go then
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
why not just do
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }
Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists.
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
You can use default cases with your method like this: var %a = $1
goto %a
:001
{ return we got 001 | goto break }
:002
{ echo -a Something else | goto break }
:%a
{ default case code here }
:break
|
|
|
|
Joined: Mar 2006
Posts: 392
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Mar 2006
Posts: 392 |
why not just do
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }
Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists. I'm using it to display all error messages in a large script You can use default cases with your method like this: var %a = $1
goto %a
:001
{ return we got 001 | goto break }
:002
{ echo -a Something else | goto break }
:%a
{ default case code here }
:break Very nice idea... Dont know why I didnt think of that... Imma use it :P
[02:16] * Titanic has quit IRC (Excess Flood)
|
|
|
|
MeStinkBAD
|
MeStinkBAD
|
why not just do
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }
Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists. The amount of code is irrelevant. It's about clean looking code that can be easily understood by a quick glance. Cleaner code makes it easier to spot mistakes, resolve bugs, and just have a better idea of what the code is designed to do. It also makes code simpler to edit or extend.
|
|
|
|
Joined: Jul 2006
Posts: 4,022
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,022 |
The amount of code is irrelevant. It's about clean looking code that can be easily understood by a quick glance. Cleaner code makes it easier to spot mistakes, resolve bugs, and just have a better idea of what the code is designed to do. It also makes code simpler to edit or extend. This is true, and that's why i agree with argv0, use if/esleif instead of your horrible thing is really much cleaner, more easy to read/edit/extend and i would have a better idea about what the code do with if/elseif rather than with something else.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Dec 2002
Posts: 2,884
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
if/elseif is not the same as a select statement. Each case of a select statement cascades into the next unless explicitly told not to - this behaviour scales very poorly using if's both in terms of code readability and efficiency. Goto is the only reasonable alternative currently, but that has a number of serious limitations too.
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
People rarely intentionally make use of switch cascading, though it's the only benefit. I'll bet the OP of this thread wasn't planning on it...
So the real benefit you get out of one use case is marginal, and if statements really aren't any more unreadable than goto switches when used normally. Like I said before, you don't want to have 10+ consecutive if statements in ONE alias/event just like you don't want to have 10+ consecutive switch cases in one alias/event.. they're both going to be equally large and unmanageable chunks of code. It's not about syntax, it's about size.
|
|
|
|
Joined: Apr 2004
Posts: 755
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 755 |
Then again using cascading to your benefit could possibly be a very efficient and descriptive way of writing a routine. It's funny that in languages that do have switch/select statements alot of whisper hits the scene to get rid of elseif'ing as coding practise. Funny sidenote: VB's Select case doesnt even cascade. For that reason if this ever were to be implemented we should stick to switch/case/default as keywords and starbucks_maffia suggestion:
In addition to the switch/case/default suggestion here I'll tag on a suggestion for an "else" clause in place of "default" which only triggers if no other cases have triggered (basically a "default" which can't be cascaded into).
definitely has my vote.
Last edited by Mpdreamz; 31/07/08 09:31 PM.
|
|
|
|
|