mIRC Home    About    Download    Register    News    Help

Print Thread
#259826 02/02/17 07:29 AM
Joined: Aug 2016
Posts: 57
R
Babel fish
OP Offline
Babel fish
R
Joined: Aug 2016
Posts: 57
I noticed a code evaluation error that I do not know if it is a language limitation, a bug or bad programming practice.

This code is to simulate the situation, I know I could have written the code differently, but in a hurry, I ended up writing like this.
Code:
//var %x = 500 | while (%x) { dec %x | echo -a %x | if (%x == 400) { break } }

When evaluating the code, it does not obey the hierarchy of brackets and breaks the while, because it considered the second statement (if) as true, but it is false.

Solution was to use:
Code:
//var %x = 500 | while (%x) { dec %x | echo -a %x | if (%x == 400) { break } | noop }


In remotes or aliases it works like this:
Code:
var %x = 500
while (%x) {
  dec %x
  echo -a %x
  if (%x == 400) {
    break
  }
}


I know I could have coded like this:
Code:
//var %x = 500 | while (%x) && (%x != 400) { dec %x | echo -a %x }

But as I said, was in a hurry...

Why do I think it's a bug?
Because the second statement (if) is giving as true, but it is false.

Now see the code below:
Code:
//if (1 == 1) { echo -a firts statement true | if (1 == 2) { echo -a second statement true } }

Here no printing occurs of "second statement true", unlike the first code with break.

Last edited by rockcavera; 02/02/17 07:33 AM.

rockcavera
#Scripts @ irc.VirtuaLife.com.br
Joined: Aug 2016
Posts: 57
R
Babel fish
OP Offline
Babel fish
R
Joined: Aug 2016
Posts: 57
In fact the code is broken not by the break, because it was not even considered true the if...

However, this code should not print the second statement, but prints:
Code:
//if (1 == 1) { echo -a firts statement true | if (2 == 2) { echo -a second statement true } }

Last edited by rockcavera; 02/02/17 07:48 AM.

rockcavera
#Scripts @ irc.VirtuaLife.com.br
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Thanks for your bug report. This has been fixed for the next beta. However, the if/while parser is complicated due to the way the scripting language evolved which means that small changes can have subtle side-effects. This fix passes my 50+ test cases of complex/multi-level/convoluted if/while statements but will need further testing.


Link Copied to Clipboard