# Help reading an evaluation expression

#### jdhughen

I have bit of code that I'm trying to understand and just can't get to where it makes sense for me. If i can get where i can understand how to interate this i can figure out how to read some of the others i'm working with.

I have got thru the documentation and think i have figure out all the operators, but just can't put it together into a "If then" type expression that make sense to me.

as it's written
Code:
``(A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ abs 7 &lt; (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ 11.5 &lt; &amp;&amp; (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ -5.5 &gt; &amp;&amp; if{ 1 (&gt;(L:VectorOnGlass, enum))} els{ 0 (&gt;(L:VectorOnGlass, enum)) }``
I added the "()" for the local Vars, and put it in Infix2Postfix and converted it back from the reverse polish notation format and got this
Code:
`````` abs( ( /-/ rddg( atg2( (A:VELOCITY BODY X , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) ) 7 &lt ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) 11.5 &lt &amp &amp ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) -5.5 &gt &amp
if &amp
{     1 &gt (L:VectorOnGlass , enum)
} else
{     0 &gt (L:VectorOnGlass , enum)
}``````
So i can see that if the evaluation of the expression is true it sets the "L:VectorOnGlass" flag.
I started in the middle of the () and worked out. I have used Bold Italics in places where I need help.

starting at the top:
*******************
Absolute value of (negate(radians to deg (in radians - ArcTangent2 of ( VBody X , VBody Z in meters/sec ??)))) --- I think this is right although i don't know why you would bother to negate a number you are going to take the absolute value of? also while the SDK list A:Velocity Body X as feet per second, i assume that the ",m/s" parameter request changes that to meters/sec ?

7 &lt -- would this read, previous is (less than) < 7 ?? or does the < connect to the next section of the expression as in "previous < following" ?

then....
Negate(radians to Deg(in radians - ArcTangent2 of ( VBody Y , VBody Z in meters/sec ??)))

11.5 &lt &amp &amp -- I am totally confused here please help. Does the double &amp mean , if the previous is true AND the following is True ??

then....
Negate(radians to Deg(in radians - ArcTangent2 of ( VBody Y , VBody Z in meters/sec ??)))

-5.5 &gt &amp - greater than something ? I can't get a grip on the "&amp" thing and how it connect things together

if &amp -- If True

set flag to 1
else
set flag to 0
************************

If someone could please fill in the blanks for me here and set me on the right path.

thanks
Joel

#### WarpD

Code:
`````` if ( ( ( abs( ( /-/ rddg( atg2( (A:VELOCITY BODY X , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) ) < 7 ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) < 11.5 ) ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) > -5.5 ) ) (
{    > 1 ) (L:VectorOnGlass , enum)
} else (
{    > 0 ) (L:VectorOnGlass , enum)
}``````

#### tgibson

According to the SDK all these units are identical:

meter per second, meters/second, m/s

&amp ;&amp ; (without the spaces) means &&, which according to the SDK means: AND

that's it - it just means AND. So the top two conditions on the stack must both be true for the result to be true.

Hope this helps,

#### Ronald

Resource contributor
I have bit of code that I'm trying to understand and just can't get to where it makes sense for me.
Is this fragment from C++, XML? a mix of both? or another programming language?

Here are some ESP SDK links that might be helpful decoding this fragment:
- https://msdn.microsoft.com/en-us/library/cc526958.aspx - Creating XML Gauges
- https://msdn.microsoft.com/en-us/library/cc526953.aspx - Creating C++ Gauges
- https://msdn.microsoft.com/en-us/library/cc526981.aspx - Simulation Variables
- https://msdn.microsoft.com/en-us/library/cc526980.aspx - Event ID's

#### taguilo

Resource contributor
I added the "()" for the local Vars, and put it in Infix2Postfix and converted it back from the reverse polish notation format and got this
I don't recommend that conversion because, as you can see, most of times gives wrong results, like in this case.

IMO the best mode to understand a script like that is to separate it in parts according to evaluators/conditionals/assignments present in the code.

So let's analyze your script. We will find:

Values
=====
(A:VELOCITY BODY X, m/s)
(A:VELOCITY BODY Z, m/s)
(A:VELOCITY BODY Y, m/s)
7
11.5
-5.5

Operators
======
atg2
rddg
/-/
abs

Evaluators
=======
&lt; (lower than)
&amp;&amp (and)

Conditionals
=======
if{}
els{}

Assignments
========
(&gt;L:VectorOnGlass, enum)

First, you split the code using the evaluators as a reference:

Value = (A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ abs Lets call it [EV1] (/-/ operator is redundant)
Evaluator = 7 &lt;

Value = (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ Let's call it [EV2]
Evaluator = 11.5 &lt;

Value = same as [EV2]
Evaluator = -5.5 &gt;

Now you insert the &amp;&amp; (and) evaluator:
[EV1] 7 &lt;
[EV2] 11.5 &lt;
&amp;&amp;

Meaning "if [EV1] is lower than 7 and [EV2] is lower than 11.5 then result is 1, else is 0" . Let's call this result [EV3]

Then it comes the second &amp;&amp; (and) evaluator:
[EV3] [EV2] -5.5 &gt; &amp;&amp;

Meaning "if [EV3] is 1 and [EV2] is greater than -5.5 then result is 1, else is 0" . Lets call this result [EV4]

Finally you have
[EV4] if{ 1 (&gtL:VectorOnGlass, enum) } els{ 0 (&gt;L:VectorOnGlass, enum) }

Meaning "if [EV4] is 1 then assign 1 to (L:VectorOnGlass, enum) else assign 0 to (L:VectorOnGlass, enum)"

With this simple method you will be able to decipher complex scripts without needing for an -erratic- Infix2Postfix conversion.

Once you adquire experience you'll find that is much easier to handle these kind of scripts in their "compact" version:

Code:
``````  (A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg abs sp0
(A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ sp1
l0 7 &lt; l1 11.5 &lt; and  l1 -5.5 > and (>L:VectorOnGlass, enum)``````
Using registers (s0...s49) and direct boolean (1-0) assignments.

Tom

Last edited:

#### jdhughen

Thank you all for the timely responses. it all makes more sense now.
Yes this is all XML gauge code (FS9 schema)

i just want to make sure I have this 1 thing right....

When you see &amp;&amp; in a script it means AND as in together or Also or "this AND that" not a AND operator, like a bitwise AND function ?

If so then then writing an expression you could use &amp;&amp; to string several conditional evaluations together that all need to be true to get an overall true result ?

Also Tom, thanks for the detail process it makes sense now. your streamlined version of the code does lead me to a couple of question about (s0...s49) registers. mainly how long do they hold their value for ? I have several pieces that are moved around by the exact same wordy lengthy expression. Currently I have all that code applied to each piece (ie BMPs, each in it's on element but all children of the same parent element). As in your example could i evaluate once storing the result in a couple registers and apply the result to all the pieces separately or would it be better to use L:vars for this type temp of storage expression evaluations ?

Joel

#### jdhughen

Code:
`````` if ( ( ( abs( ( /-/ rddg( atg2( (A:VELOCITY BODY X , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) ) < 7 ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) < 11.5 ) ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) > -5.5 ) ) (
{    > 1 ) (L:VectorOnGlass , enum)
} else (
{    > 0 ) (L:VectorOnGlass , enum)
}``````
This make's total sense and is a lot easier to read to me that what i stated with. so when writing XML in FSX9 schema can you use < , > , instead of &lt , &gt ?

Joel

#### tgibson

You can use > but you cannot use <, because it triggers an error.

And technically false is 0 and true is "non zero". It doesn't have to be 1.

#### n4gix

Resource contributor
When you see &amp;&amp; in a script it means AND as in together or Also or "this AND that" not a AND operator, like a bitwise AND function ?
A double-ampersand '&&" is a logical 'and'
A single ampersand '&' is a bitwise 'and'

For both convenience, clarity and my own continued sanity, I use exclusively the textural 'and' and 'or' when scripting logic.
If so then then writing an expression you could use &amp;&amp; to string several conditional evaluations together that all need to be true to get an overall true result ?
Yes. However such expressions use the Reverse Polish formation: (Condition1) (Condition2) and
Also Tom, thanks for the detail process it makes sense now. your streamlined version of the code does lead me to a couple of question about (s0...s49) registers. mainly how long do they hold their value for ?
Stack Registers (of which you are limited to 50), are global only within the scope of a single xml 'gauge'. They cease to exist once the gauge is unloaded of course.

#### jdhughen

I use exclusively the textural 'and' and 'or' when scripting logic.
Bill,

So just to be clear if you use textual "and" "or" we are talking logical operators and not bitwise?

So with stack registers, if you had the same expression that was applied to shift calculation of 6 or 7 different bmps each cycle thru the code is there a significant enough savings in cpu clicks to employ the use of stack registers so the script only evaluates once ? and are stack registers faster/better/resource friendler over say use L:vars if you only need them while the gauge is working. ?

Thanks
Joel

#### jdhughen

You can use > but you cannot use <, because it triggers an error.
So is that because we are talking about XML and the parser thinks your opening a tag ?
Would "<" be valid in C++ ?

Joel

#### Ronald

Resource contributor
Yes this is all XML gauge code (FS9 schema)
Thanks for the feedback on this code-fragment.

Question (to all): What is the best place to start learning, understanding XML for FS9/X?

#### vololiberista

Thanks for the feedback on this code-fragment.

Question (to all): What is the best place to start learning, understanding XML for FS9/X?
The place where you go when nature calls

#### taguilo

Resource contributor
So with stack registers, if you had the same expression that was applied to shift calculation of 6 or 7 different bmps each cycle thru the code is there a significant enough savings in cpu clicks to employ the use of stack registers so the script only evaluates once ? and are stack registers faster/better/resource friendler over say use L:vars if you only need them while the gauge is working.

Tom

#### n4gix

Resource contributor
Bill,

So just to be clear if you use textual "and" "or" we are talking logical operators and not bitwise?
Yes, those are logical operators.

I can count the number of times I've needed to resort to bitwise operations on one finger... I'm joking of course, but not more than a few hands worth of fingers!

#### jdhughen

I don't recommend that conversion because, as you can see, most of times gives wrong results, like in this case.

IMO the best mode to understand a script like that is to separate it in parts according to evaluators/conditionals/assignments present in the code.
Tom
Tom,
Thanks again for this detailed explaination. I have printed it out and taped it up on my project board.

So could you use a similar process to write scripts in RMP? or does the Infix2Postfix work any better go "to" RPN than "from"?

Joel