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

MSFS help to understand the code

Messages
44
Country
italy
hi all,
I'm not expert of coding and in my aircraft I'm doing a custom animation for my canopy. It works but not well as I need .
To make it works I have took parts of code from other aircraft and I have assembled in this way the animation.

Just to fix my custom code to do work the canopy as I need , I ask to someone expert in code , to explain me if possible , the meaning of this instruction ( in bold ) , so If I able to understand it I can think how to modify in some way this code so to optimize my canopy animation.

<PartInfo>
<Name>Canopy_int</Name>
<AnimLength>100</AnimLength>
<Animation
<Parameter>
<Code>
(L:CanopyHandle, bool) 100 * == (A:SIM ON GROUND, Bool) == (A:ENG COMBUSTION:1,bool) ! and (A:AIRSPEED TRUE, Knots) 30 &lt; and if{ 100 } els{ 0 }
</Code>
<Lag>50</Lag>
</Parameter>
</Animation>
</PartInfo>

I think I understand that: "I can manage canopy handle if my aircraft is on ground , if the engine it's not running and the airspeed it's not over 30 kt ... I don't understand the final with "if... else .." and I don't understand well the first part, " .... bool ) 100 * "
bool meaning to use 1 or 0 ?

Hope someone could help me to understand
THANKS
 
I will try to help.

First it looks like you are missing a > at the end of <Animation
Should be <Animation>

The code you are referencing is what is called Reverse Polish Notation (yes a bad term in todays world) Short form is RPN.
This coding style (language) uses the computer stack memory. Think of a stack of plates in a kitchen cupboard. The only plate available to you to take is the one on top (yes you can cheat and grab one from the middle- but your kitchen cupboard keeps those plates protected. You can't grab those.

(L:CanopyHandle, bool) 100 * == (A:SIM ON GROUND, Bool) == (A:ENG COMBUSTION:1,bool) ! and (A:AIRSPEED TRUE, Knots) 30 &lt; and if{ 100 } els{ 0 }

There ar L Var (L:CanopyHandle, bool) and A vars (A:SIM ON GROUND, Bool), (A:ENG COMBUSTION:1,bool), (A:AIRSPEED TRUE, Knots)
There are code functions like:

*
==
and
!&lt;
if{ }
els{ }


RPN reads your code line from left to right
The first thing it sees is an LVar (L:CanopyHandle, bool) - so this is put on the stack - At this point in time the stack (of plates) is empty and we add a plate (the Lvar)
The next value to put on the stack is 100
The next thing is the code function *, the multiply function. The multiply function needs two variable. It gets these variables from the stack memory. So 100 is on top and (L:CanopyHandle, bool) is underneath it (remember stack of plates).
We "pop" these two values off the stack, multiply them together and put the result back on the stack.
Now a bool type is a number either zero (false) or one (true) so somewhere else you should have code that changes this LVar from 1 to 0 or 0 to 1
When a bool is multiplied by a constant (100) we have zero times 100 results in zero or we have one times 100 results in100.
Now your next term is ==, but this term is incorrect here. == is looking for two variables on the stack - you only have one at this point. The == function is a test of equality. (is A equal to B)
Your next term is (A:SIM ON GROUND, Bool) , this is put on the stack so now you have two variables on the stack.
The next thing is another == so we compare the (A:SIM ON GROUND, Bool) to the result that was placed on the stack from before. (L:CanopyHandle, bool) 100 * == (its either a zero or 100), but comparing a bool to 100 is not right either.
This code is just not going to work.

I assume you want to open the canopy only if the aircraft is on the ground, and if the engine is not running, and if the airspeed is less than 30 knots?
What you need to do is fill up the stack with all these variables and test them.

(A:SIM ON GROUND, Bool) (A:ENG COMBUSTION:1,bool) ! * (A:AIRSPEED TRUE, Knots) 30 &lt; and if{ 100 } els{ 0 }

This puts (A:SIM ON GROUND, Bool) - which is zero or one (0 or 1) onto the stack
then (A:ENG COMBUSTION:1,bool) is put on the stack
then it is negated - turned from zero to one or from one to zero.
then you multiply these two Avars together and the result (zero or one) is put back in the stack.
then you put (A:AIRSPEED TRUE, Knots) on the stack
then you put 30 on the stack - now you have three variables on the stack

STACK by position
postion 0 (top) has 30
postion 1 has (A:AIRSPEED TRUE, Knots)
postion 2 has result of (A:SIM ON GROUND, Bool) (A:ENG COMBUSTION:1,bool) ! *

then next in the code is &lt; this takes the top two items on the stack and compares them to see if the second is less than the first - is (A:AIRSPEED TRUE, Knots) less than 30 and if true puts a one on the stack (is less than 30) or a zero on the stack if false (is greater than 30)
then the next is the and code function. this take the top two values and will "and" them together - A and B - if A and B are both 1 then result is 1 - if anyone of A or B is zero then result is zero

STACK by Position
postion 0 has result of (A:AIRSPEED TRUE, Knots) 30 &lt;
postion 1 has result of (A:SIM ON GROUND, Bool) (A:ENG COMBUSTION:1,bool) ! *

It takes a lot of mind power to figure all this out. But the result of position 0 and position 1 result in one value of a zero or one.
Now the if{} els{} code function will do one of two things enclosed in the {} parts. if the result of the previous "and" in this case is 1 then the if{} part is done. If the previous "and" is zero then the els{} is done.

So depending on all these variables the result comes down to 0 or 100 as the animation code value. If 0 then the animation is at Key Frame 0 if the result is 100 then the animation Key frame is set to 100.
I have only tried to help explain how RPN works. This code may not be what you need. You will also need some mouse code to trigger the animation.
 
Last edited:
Hi @ronh ,
thank you so much for your help.
now I want to read with attention what you told me ( it’s not easy for me ) so to understand well and better this code.
yes you are right about what I need as canopy behaviour.

very kind
 
Back
Top