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"
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
It's a good idea to keep mIRC away from making it's language draw away from a C syntax, because it would benifit all who program, that way they don't have to keep on going through different help files and then get mixed up later on.

So to make it simple I believe that it would be better to just keep the language universal.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
First off, don't kid yourself.. mIRC is nothing like C.

The *only* thing mIRC shares in common with C style syntax is curly braces. Just about nothing else is C inspired. mIRC is untyped for one (let alone dynamically typed), but more specific to syntax: there's no ; command endings, no required (), no strings, no for loops, no arrays, a goto label is ":name" not "name:", functions that return values start with $, functions that dont (optionally) start with /, variables start with %, identifier (not mirc "identifiers") tokens can be any string of non-space characters in mirc, C has it well defined. There's no ON * event handling syntax. Heck, it doesn't even share all the properties of if statements: C doesn't use "elseif". Is that enough difference? If you define a language as C style based on the fact that it uses curly braces, that covers a lot of languages... languages like Tcl, for instance, which mIRC is probably more similar to.. and that language could not be less like C.

Secondly, you talk about getting mixed up-- if mIRC starts adopting C idioms when it hasn't ever done so, that's far more of a mixup to any mIRC scripter than anything else.

If anything, it's a good idea to keep mIRC using the same idioms it already is-- that would confuse no one, because it's consistent.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
*pets argv[0]*..

There there, take a nap now..

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Originally Posted By: argv0
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?

I beg to differ the case and default statement are parts inside the switch() {

}
statement so it could definitely make the distinction without breaking compatibility. mIRC would have to break switch,case & default aliases anyway so whether it breaks default or default: is of little importance.
Originally Posted By: argv0

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"


Since when has that stopped mIRC from implementing anything ? By that logic the whole on *:TEXT:*:*: concept could/should have never been implemented.

The same escape logic would apply to the case statement
"case X $+ $chr(58) says:"


$maybe
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
Quote:
First off, don't kid yourself.. mIRC is nothing like C.

You are probably right in SOME ways, since nobody's opinion will be the same, let's just end this with: "We agree to disagree."

Quote:
The *only* thing mIRC shares in common with C style syntax is curly braces.

Really? I always thought the syntax was alot like it and when I did, I didn't say all of it was exactly like it... of course! I don't really see why they put ";"'s at the end of every line. I don't see the use for it. It just makes the code look sloppy, and unreadable. (but that's my opinion, one man's junk is anothers treasure.)

Onwards...

I have seen alot of my scripts using a buttload of elseif's just because I needed to make a simple conversion table, or encryption logarithim. My example in words is that if a line starts with '-', then I want it to read the command before processes all the data it gets. So with that said, I need to use $iif or if,elseif,elseif,elseif,elseif,else statements because it is the only way to do it, for now.

Now... if we had case/switch: it would be alot easier.

For the goto loop:
If I wanted to use a goto, I would take 4 hours trying to figure out what was wrong with it then give up and do it the hard way. Right now, I don't feel like absolutely wasting 4 hours of my time when I have a life to live.

For anything else:
Just ask yourself, is there ANYTHING that can have a comeback and make sense to what I'm about to try and debate with?


Quote:
If anything, it's a good idea to keep mIRC using the same idioms it already is-- that would confuse no one, because it's consistent.

Hi there. I have seen almost every good scripting language out there. They all have one thing in common: They all confuse me.
When you talk about confusion, it's inevitable. Why keep everything the way it is and accomplish nothing and be lazy, when you can do something about it, make it better to use, and pretty much delay anything that would make anyone argue?

Personally, I really think that switch would be good for mIRC, because switch in mIRC has no equivalent yet. And another thing: If I posted every suggestion that ran through my mind, you guys would have a huge forum running. But instead, I think about what I'm going to suggest. I look at the quality of my posts, and I think: "Are people [i]really] gonna wanna read this? Or are they going to laugh at me and spit in my face?"

That is the only reason I posted here, so I have data and reason to back anything up that I say, so hit me with your best shot, and may the more experienced or more prepared win.

Point blank: I'm just trying to see what can be done to improve this for everyone, and not just myself.

Thankyou for your time, and if you reply to this and it is off topic, please PM me with it so we can talk privately, because I don't want any more spam on this thread.


PS:
I am sorry for posting something completely off-topic, just needed to clear up some spam.

Joined: Mar 2008
Posts: 93
B
Babel fish
Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
Originally Posted By: Mpdreamz
switch/case,for,foreach still high on my wishlist!


+1

Stopped counting how often I could have needed some for()-like statement, rather than using var %i = <start>, while (%i < <condition>) { <do stuff>, <change> %i }

Greetings, BhaaL

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
CASE isn't the same as FOR. FOR and WHILE are pretty much interchangeable... they basically do the same thing, but are formatted differently. Case is more related to just IF/ELSEIF/ELSE.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
CASE is also relatively interchangeable except for fallthroughs though fall throughs can be done with nested ifs


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Right. I wasn't meaning it wasn't interchangeable... just not with FOR.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2007
Posts: 13
I
iStink Offline OP
Pikka bird
OP Offline
Pikka bird
I
Joined: Aug 2007
Posts: 13
Some people say that it's just the same as using an if statement.
Well; What if you have 40 things you want to check?
Code:
if this { do this
and this
and this 
and this
}

40 times does not seem pleasant.

But, even though using the goto loop, it would just make the code longer and take much more time to parse rather than just doing it.


Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Nobody said it was the same syntactically. Semantically, however, you're doing the same thing with a set of if statements.


- 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