mIRC Home    About    Download    Register    News    Help

Print Thread
$v1/$v2 inconsistancy #261001
14/07/17 06:55 PM
14/07/17 06:55 PM
Joined: Apr 2010
Posts: 910
USA
F
FroggieDaFrog Offline OP
Hoopy frood
FroggieDaFrog  Offline OP
Hoopy frood
F

Joined: Apr 2010
Posts: 910
USA
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
Re: $v1/$v2 inconsistancy [Re: FroggieDaFrog] #261002
15/07/17 01:13 AM
15/07/17 01:13 AM
Joined: Apr 2010
Posts: 910
USA
F
FroggieDaFrog Offline OP
Hoopy frood
FroggieDaFrog  Offline OP
Hoopy frood
F

Joined: Apr 2010
Posts: 910
USA
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
Re: $v1/$v2 inconsistancy [Re: FroggieDaFrog] #261004
15/07/17 01:51 PM
15/07/17 01:51 PM
Joined: Dec 2002
Posts: 4,449
London, UK
Khaled Offline

Planetary brain
Khaled  Offline

Planetary brain

Joined: Dec 2002
Posts: 4,449
London, UK
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.

Re: $v1/$v2 inconsistancy [Re: Khaled] #261006
15/07/17 07:25 PM
15/07/17 07:25 PM
Joined: Apr 2010
Posts: 910
USA
F
FroggieDaFrog Offline OP
Hoopy frood
FroggieDaFrog  Offline OP
Hoopy frood
F

Joined: Apr 2010
Posts: 910
USA
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
Re: $v1/$v2 inconsistancy [Re: FroggieDaFrog] #261007
16/07/17 09:22 AM
16/07/17 09:22 AM
Joined: Dec 2002
Posts: 4,449
London, UK
Khaled Offline

Planetary brain
Khaled  Offline

Planetary brain

Joined: Dec 2002
Posts: 4,449
London, UK
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.

Re: $v1/$v2 inconsistancy [Re: Khaled] #261045
20/07/17 07:13 AM
20/07/17 07:13 AM
Joined: Feb 2003
Posts: 2,600
Raccoon Online
Hoopy frood
Raccoon  Online
Hoopy frood

Joined: Feb 2003
Posts: 2,600
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!
Re: $v1/$v2 inconsistancy [Re: Raccoon] #261047
20/07/17 07:38 AM
20/07/17 07:38 AM
Joined: Dec 2002
Posts: 4,449
London, UK
Khaled Offline

Planetary brain
Khaled  Offline

Planetary brain

Joined: Dec 2002
Posts: 4,449
London, UK
The issue is not related to $v1/$v2. Please see my previous posts.