Is it possible the RPN 'AND' operator isn't working in 2020 or 2024?

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.

   <Component ID="B21_TEST_AND">
        <UseTemplate Name="ASOBO_GT_Update">
            <FREQUENCY>30</FREQUENCY>
            <UPDATE_CODE>
                0 1 AND (&gt;L:B21_TEST_AND)
            </UPDATE_CODE>
        </UseTemplate>
    </Component>

In 2020 behaviours tool:

In 2024 behaviours tool:

The fallback would be to use nested `if`` blocks.

I didn’t check OR.

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.

1 Like

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.

Yep that look s strange, but I don’t believe it’s a bug.

what happens if you give it a unit

0 1 AND (&gt;L:B21_TEST_AND, number)

or reduce the frequency

edit: What happens if you force change it in the debug local variables tab?

or add a

        <UseTemplate Name="ASOBO_GT_Update">
                  <UPDATE_ONCE>TRUE</UPDATE_ONCE>
            <UPDATE_CODE>
                5 (&gt;L:B21_TEST_AND, number)
            </UPDATE_CODE>
        </UseTemplate>

or reverse the 0 1 to 1 0

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?

1 Like

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 (&gt;L:B21_TEST_01_AND)
	               0 1 and (&gt;L:B21_TEST_01)
	               1 0 AND (&gt;L:B21_TEST_10_AND)
	               1 0 and (&gt;L:B21_TEST_10)
	               1 1 AND (&gt;L:B21_TEST_11_AND)
	               1 1 and (&gt;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 &amp;&amp; and that is just absurd.

image

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.

1 Like

I gave it a quick try while I was already in the sim… sure enough it does give a console message as well:


And in the logger:
image

This seems to apply to all operators, so a documentation fix would seem in order. Nice find B21 :+1: .

2 Likes

Hi everyone,

We will get the documentation fixed, thanks for reporting.

Best regards,

Eric / Asobo

1 Like