mIRC Home    About    Download    Register    News    Help

Print Thread
#261001 14/07/17 06:55 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Dependent on parens, $v1 and $v2 are set to different values for the same condition:

Code:
;; 1 - 2
if 1 == 2 || 2 == 2 echo -a $v1 - $v2
if (1 == 2 || 2 == 2) echo -a $v1 - $v2

;; 1 - 1
if 1 == 1 && 2 == 2 echo -a $v1 - $v2
if (1 == 1 && 2 == 2) echo -a $v1 - $v2

;; 2 - 2
if 1 == 2 || 2 == 2 { echo -a $v1 - $v2 }
if (1 == 2 || 2 == 2) { echo -a $v1 - $v2 }
if (1 == 2) || (2 == 2) echo -a $v1 - $v2
if (1 == 2) || (2 == 2) { echo -a $v1 - $v2 }

;; 2 - 2
if 1 == 2 && 2 == 2 { echo -a $v1 - $v2 }
if (1 == 2 && 2 == 2) { echo -a $v1 - $v2 }
if (1 == 2) && (2 == 2) echo -a $v1 - $v2
if (1 == 2) && (2 == 2) { echo -a $v1 - $v2 }


Its expected that all should result in $v1,$v2 being set to 2

This may very well be related to an underlying issue with the OR operator where:
- if the last condition of an if-statement makes the if's overall condition truthy mIRC has no problem with processing
- if a condition in the middle of the statement would make the if's overall condition truthy mIRC raises an error

Code:
;; these process the condition without issue (but sets $v1,$v2 incorrectly)
if 1 == 2 || 3 == 3 /noop
if 1 == 1 || 2 == 3 { noop }

;; These raise an "/if: ambiguous format" error
if 1 == 1 || 2 == 3 /noop
if (1 == 1 || 2 == 3) noop

Last edited by FroggieDaFrog; 15/07/17 12:46 AM.

I am SReject
My Stuff
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
More cases:

Code:
;; 1 - 2 (incorrect)
if (1 == 2) || 2 == 2 echo -a $v1 - $v2

;; 1 - 1 (incorrect)
if (1 == 1) && 2 == 2 echo -a $v1 - $v2

;; 2 - 2 (correct)
if 1 == 2 || (2 == 2) echo -a $v1 - $v2
if (1 == 2) || 2 == 2 { echo -a $v1 - $v2 }

;; 2 - 2 (correct)
if 1 == 1 && (2 == 2) echo -a $v1 - $v2
if (1 == 1) && 2 == 2 { echo -a $v1 - $v2 }


An observation: Wrapping the command body in {}'s seems to remove all strangeness thus $v1/$v2 are set to expected/consistent values for the same condition block regardless of how the block is formatted with ()'s [assuming that the alternative formatting of the condition does not change how its processed]

Last edited by FroggieDaFrog; 15/07/17 02:01 AM.

I am SReject
My Stuff
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Thanks for your bug report. This is not actually related to $v1 and $v2. As you discovered, when you use the ()/{} brackets, $v1 and $v2 are correct. The reason for this is that without the ()/{} brackets, the if statement does not know where the if comparison ends. So it has to keep evaluating the line until it finds the enclosing ()/{} brackets. In this case, $v1 and $v2 are evaluated during if processing, in an attempt to determine the second set of comparison parameters.

mIRC has to allow non-use of ()/{} brackets for backwards compatibility because that is how the if constuct was originally implemented, however as mentioned in the help file, ()/{} should be used as much as possible to prevent ambiguity.

Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
With what you said, shouldn't this example from above have set $v1,$v2 correctly:

Code:
;; 1 - 1; should be 2 - 2
if (1 == 1 && 2 == 2) echo -a $v1 - $v2


I'm not suggesting enforcing ()/{} but $v1,$v2 should be consistently set to the last condition processed. In the case above its as though mIRC is exiting the condition processing before setting $v1,$v2 to the 2nd condition.

Last edited by FroggieDaFrog; 15/07/17 07:27 PM.

I am SReject
My Stuff
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Same issue as above - the entire line is being parsed. This cannot be changed without breaking legacy code. You will need to use ()/{} brackets for the expected behaviour.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Khaled, wouldn't it make sense for state of $v1 and $v2 ($ifmatch) to be updated in relation to the actual intelligence of if-condition success and failure processing? What people are asking is, if the mSL engine is still able to determine the ultimate success and failure of the /if statements without breakage, then why are $v1 and $v2 left stranded in another dimension?

It's as if $v1 and $v2 are being determined in an entirely separate parsing of the script line, given the inconsistencies between success of /if and fail of $v1/$v2.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
The issue is not related to $v1/$v2. Please see my previous posts.


Link Copied to Clipboard