• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX Bitmask checking in XML

Messages
1,056
Country
ca-ontario
I need to check a sim variable against a bit mask, so basically, if a variable

(A:WATER RUDDER HANDLE POSITION, number) has a value of 242, a binary format would be 11110010

I need to check if bit 5 is set (it is, in this case).

What's the XML syntax for this? This needs to be in modeldef.xml file, visibility code.

Thanks,
Misho
 
Ah yes, the joy of epiphany! ;) Got it to work:

<PartInfo>
<Name>Part_001</Name>
<Visibility>

<Parameter>
<Code>
(A:WATER RUDDER HANDLE POSITION, number) 16 &amp; 16 ==
</Code>
</Parameter>
</Visibility>
</PartInfo>

This code checks if the bit 5 in the variable is set. The variable (when accessed from SimConnect) is of the long double type (64 bits), however, XML code recognises only first 32 bits and ignores the rest of them. Is there any way to make XML read the full precision of the long double variable?

Misho
 
Last edited:
Wouldn't this be quite pointless when the actual simulator is a 32 bit program?
 
No, not at all. I am "hijacking" this variable in order to implement extra functionality and I need every bit I can find. Internally, the variables are 64 bits long, and In SimConnect I am setting all 64 bits on the variable without a problem. But when the variable is bit-checked in XML, only first 32 bits respond.
 
Numeric AVars are all of C++ type double (64 bits), both in C and XML. If the variable can handle 64 bits there should be a method to check them all.

Tom
 
Numeric AVars are all of C++ type double (64 bits), both in C and XML. If the variable can handle 64 bits there should be a method to check them all.

Tom

Thanks Tom... Yeah, that's what I thought, but for instance, this code:

(A:WATER RUDDER HANDLE POSITION, number) 68719476736 &amp; 68719476736 ==

Is checking for 36th bit in the variable (I know, it looks ugly, but 68719476736 is 2^36 :D) and, while it is set in SimConnect, modeldef.xml code is ignoring it. Meanwhile, checking for the 31st bit:

(A:WATER RUDDER HANDLE POSITION, number) 2147483648 &amp; 2147483648 ==

...works fine. :banghead:

Misho
 
Well, I believe the sign is giving trouble to you.

instead of using that AVar, try to set an LVar like (L:LVar,mask) and then in the gauge &amp that (LVar,mask) with a proper number.

Tom
 
Hello. I see that: (A:WATER RUDDER HANDLE POSITION, number) 16 &amp; 16 == works, but why? I don't understand the logic. To me:
rudder and 16 = 16 ??? Also, how can this be converted to a lua script? Thank you.
 
& is a BINARY operation. 16 is 000010000 (any number of bits will do for this example)

So e.g. 110110110 & 00001000 is 000010000

and 000010000 == 16 is true
 
Hello B21-soaring. Thank you for your reply. I think you cleared up the logic for me.
rudder (binary) AND 16 (binary) = 16 (binary) and if it = 16 (binary), then TRUE. So how is that done in a lua script? So far,
I'm able to get the variable to a binary value but struggling on the comparison/AND in a lua script...
And finally, got it. Even though the lua is doing a decimal to binary conversion, the result is a text value. Once I realize that, I was able to parse the needed data using: string.sub :) Thanks again B21-soaring, because the XML logic threw me for a loop. Oky, got it. Lua has the operator "logic.And." This works as the same logic used in the XML. Couldn't have done it with your help B21-soaring! Stll though, that works great to compare, but how do you insert a binary value(s) into say: (L:BinaryValue,number)? For example, one condition 1, value = 1, condition, value = 10, condition 3, value = 100, etc.?
I tired this to no avail (plus other combinations):
condition 1 is true if{ 1 1 &amp; (&gt;L:BinaryValue,number)
condition 2 is true if{ 2 2 &amp; (&gt;L:BinaryValue,number)
condition 3 is true if{ 4 4 &amp; (&gt;L:BinaryValue,number)

Getting closer. Learned how to set and clear bits... That is the key...
 
Last edited:
Back
Top