• 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.

P3D v4 XML Coding Question

Messages
159
Country
us-colorado
I ran across a code block with the structure below. The first if statement strikes me as odd. While I guess the code works as intended, is there some advantage that makes using the first if statement a better choice than a simple and statement like (A:ELECTRICAL MAIN BUS VOLTAGE,Volts) 3.0 > and ?
Thx,
Al


Code:
<Element>
   <Select>
     <Value>

    (L:Var1,bool)
    (L:Var2,bool) or
    (L:Var3,bool) or
    if{ (A:ELECTRICAL MAIN BUS VOLTAGE,Volts) 3.0 &gt; }

    if{ 1 (>L:Var4,Bool) } els{ 0 (>L:Var4,Bool) }

     </Value>
   </Select>
</Element>
 

Vitus

Resource contributor
Messages
1,480
Country
newzealand
You're correct.
This might potentially trigger undefined states as well - when Var1, Var2 and Var2 are 0.
The only reason I could think of why someone would write it like this, is to be more clear about the order of things. A ˅ B ˅ C ˄ D is not the same as (A ˅ B ˅ C) ˄ D. But in the case of the P3D/FSX xml code, the example would be read as the later, so you're good.

Your way is more defined and easier to read imho.
 
Last edited:
Messages
159
Country
us-colorado
This might potentially trigger undefined states as well - when either Var1, Var2 or Var3 are 0
Could you explain a little more about this? Turns out the reason I am looking at this code is I'm trying to track down a 'bug' that only happens rarely, so I'm interested in your comment about the potential for undefined states. Regarding the first 3 lines of code above, I would have written them as

Code:
    (L:Var1,bool) 1 ==
    (L:Var2,bool) 1 == or
    (L:Var3,bool) 1 == or

So is your comment on potential undefined states about the lack of explicitly testing the Lvars for 1?

Thanks for the help,
Al
 

Vitus

Resource contributor
Messages
1,480
Country
newzealand
Understand what the xml-interpreter is doing with the code.
  • (L:Var1,bool) loads the value of L:Var1 into the stack
  • 1 loads "1" into the stack
  • == compares the last two entries of the stack and return 0 if they're different, 1 (or something else) if they're the same. So after the first line, either "0" or something else (probably "1") is in the stack. Let's assume it's "1" and continue...

  • (L:Var2,bool) loads the value of L:Var2 into the stack
  • 1 loads "1" into the stack
  • == compares - as before. So after the == your stack will consists of the "1" from before and then either a "0" or something else for the second comparison. Let's assume this value is "1" as well.
  • after the or, the stack is cleared and there's either a "0" or "1" in the stack, based on the or-evaluation.

  • continue for the var3....

Soooo assume that Var1, Var2 and Var3 are all "0". After this block:
Code:
    (L:Var1,bool) 1 ==
    (L:Var2,bool) 1 == or
    (L:Var3,bool) 1 == or
There will be a "0" in the stack. The next line of code is:
Code:
if{ (A:ELECTRICAL MAIN BUS VOLTAGE,Volts) 3.0 &gt; }
And since there's a "0" in the stack, the if{ - statement is not performed, but the stack is emptied!
Next, you have:
Code:
if{ 1 (>L:Var4,Bool) } els{ 0 (>L:Var4,Bool) }
but in our example, the if{ statement has nothing in the stack and so it can go either way. It's an undefined state.

And just on a side-node: understand that only the "FALSE" state of a boolean expression is properly defined. So it's always safer to check for "0" or "not 0" when evaluating boolean expressions.

The solution to this is what you proposed, and extended to make it more robust:
Code:
    (L:Var1,bool) 0 !=
    (L:Var2,bool) 0 != or
    (L:Var3,bool) 0 != or
    (A:ELECTRICAL MAIN BUS VOLTAGE,Volts) 3.0 &gt; and
    if{ 1 (>L:Var4,Bool) }
    els{ 0 (>L:Var4,Bool) }

In this case, there are no undefined states, since the first four lines will leave either a "0" or something else (most likely a "1") in the stack. Hence, the if/els will evaluate properly. I hope this helps!
 
Top