mIRC Home    About    Download    Register    News    Help

Print Thread
#232920 29/06/11 08:50 PM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Well, the help file only states that the semi colon used to make a comment must start the line, so maybe this is not a bug but it is known that in the middle of a line, the semi colon makes it so the parser ignores that command only:
Code:
alias whatever { echo -a 1 | ;echo -a 0 | echo -a 1 }
However, when if statement are involved with multiple command and a semi colon is used to comment the last command, there is a problem:
Code:
alias test {
  if (1 == 2) { noop | ;noop | noop }
  elseif (1) echo -a ok 
}
works, but
Code:
alias test {
  if (1 == 2) { noop | noop | ;noop }
  elseif (1) echo -a ok 
}
doesn't

I use that behavior and it took me quite some time to understand why my elseif suddendly stopped working, so I thought I would report it.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Technically speaking "| ;echo -a 0" isn't supposed to work either, so you shouldn't trust it to.

But I guess this could be fixed and maybe the documentation can be changed to officially support ; in the middle of a line.


- 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
I'm sure mIRC is looking at that and treating the |'s like they are meant to be... basically creating a new line. As such, ; after a | works as a comment for that specific command. However, your last example, the ; would comment not just noop, but also the end bracket, which of course messes up the code. That makes sense based on the code. If you were to put a | before the final bracket on that line, it would probably work as you are wanting.

I'm not really sure if that should be changed. ; should comment the entire line. With |'s, the entire line is what is between one | and the next (or the end of the line). Otherwise, you're going to have to treat mid-line ;'s differently than beginning-line ;'s because you'd have to tell mid-line ;'s to NOT comment a } . I'm not really sure that's a good idea.

I'm trying to think of other languages with mid-line commenting and can't come up with any off the top of my head. There's end-line commenting in some languages. There might be mid-line commenting in some languages in the form of /* */ , but that has an END, whereas ; does not.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Quote:
However, your last example, the ; would comment not just noop, but also the end bracket. That makes sense based on the code. If you were to put a | before the final bracket on that line, it would probably work as you are wanting.
Yeah.. It's exactly what I'm reporting/asking to be changed


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Right, but see my second paragraph above.

Right now, mIRC treats a | the same as $crlf (at least, that is how it appears). For the ; in your last example to work, Khaled can't just tell it to ignore an ending }. That would break the normal ; at the beginning of a normal line. He'd have to basically make ; behave two very different ways. I really don't think that's a good idea.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Look, my first post shows that
Code:
alias whatever { echo -a 1 | ;echo -a 0 | echo -a 1 }
works as I am expecting it to, commenting only that command, which therefore means that mirc is able (being intentional or not) to comment only one command when a single line involving more than one command is encoutered, and is able to comment the whole line when the ; is starting the line, regardless if the line contain some | or not.
mIRC is clearly making the difference between the two cases, now I'm asking for a little change: when commenting only one command, it should stop at a | or a }.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
this looks like a bug to me.

if mIRC entered that code block (1 == 1 instead of 1 == 2 for example) and examined each command individually, then it wouldn't ignore '}'. the problem therefore lies in mIRC's ability to identify comments in blocks of code that don't go through its command interpreter.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
EDIT: Skip down 2 posts and read that first. This still has information that you can read, but the post below explains some new findings regarding this issue that supercede what I wrote here and in the first post below.

You're missing the point. If |'s are treated by mIRC's interpreter as $crlf for all intents and purposes, then your codes break down to the following:

Code:
alias whatever { echo -a 1
  ;echo -a 0
  echo -a 1 }


As you can see, the ; comments the full "line" of code, just like normal.

Code:
alias test {
  if (1 == 2) { noop
    noop
    ;noop }
  elseif (1) echo -a ok 
}


As you can see here, ; also comments the full "line" of code, which includes a ; . If you were to write the code like this (without |'s), you would expect the ; to comment out everything on the line including the } .

Right now, it looks like mIRC is not doing anything special with the ; . It is treating it just like it is always treated when at the beginning of a line. A | acts like a new line. There is no special coding for it when it's in the middle of a line.

If a change was made, then the ; would act differently in different instances and that's rarely a good idea in a programming/scripting language. You would have the ; comment EVERYTHING on a line in one instance, but only specific things on a "line" in the other instance. Not a good idea, imo.

Yes, it can be done and probably easily. But I just don't think it's a good idea to start making things do different things in different situations.

I think it's a much better idea to have your script use the ; the way it's meant to be handled... it will comment everything on a "line" when used at the beginning of the "line". And a line is anything between a $crlf or a | and the next $crlf or |. If you want your script to work this way, just use another | to show where the line is supposed to end:

Code:
alias test {
  if (1 == 2) { noop | noop | ;noop | }
  elseif (1) echo -a ok 
}


Yes, it looks odd because you don't normally do that, but it's reasonable because without |'s, the } would usually be on the next line anyhow.

Or, if you don't like doing that, I'd recommend an in-line commenting of the sort like /* */ instead. That lets you tell mIRC where to stop the comment.

With your change, if someone comes along and wants to do something like this:

Code:
alias test {
  if (1 == 2) { noop | ;if (2 == 3) { noop } | noop }
  elseif (1) echo -a ok 
}


Then you'd be in the same situation you already are. The user means to comment the nested IF (up to the |), but because you are stopping at the }, which the user probably isn't going to understand, it will instead completel that IF and you'll be left with this...

Code:
alias test { noop
  if (1 == 2) { }
  noop
}
elseif (1) echo -a ok 
}


As you can see, the ELSEIF is no longer part of the alias. In the end, the user will be in the same situation you were in and have to keep testing to figure out why it isn't working.

Last edited by Riamus2; 30/06/11 11:43 AM.

Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Through a quick test, it looks like ; is already treated differently at the beginning of a line, so I guess that part doesn't make much difference. If at the beginning of a line, it comments the entire line including |'s.

Now, that still leaves us with the individual issues that people trying to use it in the middle of a line will have. In your case, stopping at the } makes sense. In the last example I gave above with the nested IF, it doesn't make sense to stop at the }. Because these are both edge cases that contradict each other, it is better to leave it this way because: 1) Any scripts that make use of inline ;'s the way they work now will probably break with a change, 2) Your issue can be fixed easily with the extra |, but the nested IF can't be fixed if the change is made other than to separate the lines.

I still think the best solution is to request /* */ style commenting in the middle of a line. That gives full control over where the comment starts and ends rather than having mIRC guess what you want.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok... Further testing... I decided to adjust the code you gave as any example instead of only checking what you provided.

This appears to actually only affect a FAILED IF statement.

Code:
alias test {
  if (1 == 1) { echo -a 1 | echo -a 2 | ;echo -a 3 }
  elseif (1) echo -a 4
  echo -a 5
}


This works like you expect it to. So this actually is a parsing error, but is related to a failed IF rather than just the ; . Also, this only affects a failed IF statement if the ; is in the LAST part of the IF statement's line. The ; will stop at } any other time.

*** This does invalidate what I said above because it's already set up to do things differently based on where the ; is located. I still don't think that's a good idea for the reasons listed above, but oh well. Also, this bug is a good example why having mIRC try to guess what you mean is a bad idea.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Hum, I came accross this problem again, and I once again spent quite some times figuring it out.
So yeah, whenever you have a line that is part of a whole if/elseif/else structure, and that line is parsed but ignored, if you have a block of commands on one line and if the last command of that block is commented out with a ';' (or the /rem command), the parsing is not working correctly anymore

Note the following, weird related things:
Code:
alias test_comment {
  echo -a hello
  if (1 == 2) { noop | ;r }
  else { noop | ;r }
  echo -a bye
}
/test_comment displays:
Quote:
hello
* /if: close bracket not found (line 2, script4.mrc)
line 2 being "echo -a hello".

Should this be fixed or am I not supposed to use ; to comment out that way (the undocumented /rem command behaves the same)?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Anything after a comment prefix is treated as a comment, so you should not be using it this way.


Link Copied to Clipboard