mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Dear Khaled, (edit: nevermind)

Do you expect that there should still be unresolved issues regarding simple nested while-loops (or if-checks) when scripted as single line code, or editbox code?

I don't recall if you declared these issues resolved or not.

Example:
Code:
tickstest1 {
  var %n = 100, %max = 0, %ticks, %i
  while (%n > 0) {
    set %i 1
    set %ticks $ticks
    while ($ticks == %ticks) inc %i
    if (%i > %max) set %max %i
    dec %n
  }
  echo -a * tickstest1: n= %n , i= %i , max= %max
}

tickstest2 { var %n = 100, %max = 0, %ticks, %i | while (%n > 0) { set %i 1 | set %ticks $ticks | while ($ticks == %ticks) inc %i | if (%i > %max) set %max %i | dec %n } | echo -a * tickstest2: n= %n , i= %i , max= %max }

* tickstest1: n= 0 , i= 718 , max= 786
* tickstest2: n= 98 , i= 1 , max= 268

I've tried many many variants of the above code. while (%n) vs while (%n > 0), with and without { } for the inner /while, with and without the /if (%i > %max) code, using /set instead of /var, etc. I don't get any nested while loops to work on a single line, so I assume this was never resolved or marked as unfixable?

__

Edit: maroon found that wrapping /inc %i in { } braces makes the single-line code work. Some how I assumed that did not work for me either. So I guess my question is moot but I'll leave this here to the oddities encountered, and maroon's credit.

tickstest3 { var %n = 100, %max = 0, %ticks, %i | while (%n > 0) { set %i 1 | set %ticks $ticks | while ($ticks == %ticks) { inc %i } | if (%i > %max) set %max %i | dec %n } | echo -a * tickstest2: n= %n , i= %i , max= %max }

Last edited by Raccoon; 05/01/18 11:34 PM. Reason: is not a maroon.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Khaled did fix some issues with nested while loop on single line but this is just another issue, I don't see why you are nevermind'ing it, this is a bug and should work just fine given that it works with multiple lines.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
I stumbled across this bug again, having forgotten that this issue had come up earlier.

To summarize what my testing shows, the bug is trigged where there's a /while nested inside another /while. For this to happen, the interior nested /while consists of a single command not enclosed in brackets, and is either in an editbox or is on the same scriptline line as the end-bracket ending the exterior /while. So 2 lines is enough to avoid the early exit, as long as the command is split in one of the right places.

This example alias shows it doesn't matter whether the end-bracket is on a 'normal' next-line, or is an extension of the existing line using $& to continue the same command on the next row. The red countdown exits early unless brackets are added to enclose the /noop. But the purple and green countdowns don't exit early, because the nested /while is split across the two lines:

Code:
alias nested_while {
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop | var %c $v2 | echo 4 -a i= %i $time | dec %i } | echo -a finish $time
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop
  var %c $v2 | echo 6 -a i= %i $time | dec %i } | echo -a finish $time
  var %c $ctime , %i 5 | while (%i) { while (%c == $ctime) noop | var %c $v2 | ec $+ $&
    ho 3 -a i= %i $time | dec %i } | echo -a finish $time
}

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Ouims: I don't consider it a bug because Khaled has already asked us kindly not to complain about incongruities with brace formatting omissions.

We know that WHILE is a pre-parser syntax and not regular a command. If it needs braces to support one-line nesting, then it needs braces to support one-line nesting.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Ok, well that's still a bug as far as I'm concerned so I will report it as such with maroon's addition, or maybe he will report that himself.


#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
Thanks for your post. As you noted, this issue has been discussed before and the solution is to use {} brackets. This issue is already on my to-do list.


Link Copied to Clipboard