I’ve just spent a while puzzling over a section of RPN code and crazy though it sounds (maybe it doesn’t) as far as I can tell the “logical AND” operator in RPN is broken. I.e. the logical 0 & 1 should be 0 but both MSFS2020 and MSFS2024 are computing that as 1 as far as I can tell. (Of course in RPN that’s 0 1 AND (>L:myvar) and inspect L:myvar)
This minimalist component give the reproducible error.
Apologies if I’ve totally missed something here - something so fundamental seems much more likely to be a mistake by me than that deep a bug, but when I eventually shrank my code to the above component I can’t work out how it couldn’t be a bug.
I never had a problem with logical AND in RPN but I always use the lowercase ‘and’. I know the docs show it as && or AND. If this is the case, it would be an error in the docs.
As a tip, if one of the operands is a boolean, it seems simpler to just use multiply instead of AND but of course that is just a more specific case.
I had a quick scan through the FBW XML and all instances of “and” are lowercase. I wonder if AND in uppercase is actually not recognised, discarded, and so 1 is still the value on the top of the stack when your local var is written… Anything in the console?
I did a test to see if there was a difference in these keywords. This was the code with several variations.
<Component ID="TEST">
<UseTemplate Name="ASOBO_GT_Update">
<UPDATE_ONCE>TRUE</UPDATE_ONCE>
<UPDATE_CODE>
0 1 AND (>L:B21_TEST_01_AND)
0 1 and (>L:B21_TEST_01)
1 0 AND (>L:B21_TEST_10_AND)
1 0 and (>L:B21_TEST_10)
1 1 AND (>L:B21_TEST_11_AND)
1 1 and (>L:B21_TEST_11)
</UPDATE_CODE>
</UseTemplate>
</Component>
So the results seem to conclude that AND does not actually invoke the logical AND operation. The last value in the stack is being written in the var while the “and” versions all return the correct values.
I did not try && because in XML that would be && and that is just absurd.
Now that I think about it, I must have run into this bug to have been using the lower case. I probably found a solution and didn’t give it more thought.