• 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 HeightCode not working/crashing the sim

Messages
29
Country
unitedkingdom
Hi All,

I am trying to create a hover gauge that displays a an extending or retracting line in the direction of the aircraft velocity to depict the direction of movement whilst in a hover. I think I have the basic math and mechanics right but as soon as I but a dynamic <HeightCode> in the sim crashes. I suspect I have a memory leak but can not figure it out. A static number in the heightcode, such as '50' seems to work fine and the rotation works as expected.

Any suggestions would be appreciated.

XML:
<!-- Velocity Vector Hover Modes -->
<Macro Name="X">(A:VELOCITY BODY X, knots) (A:VELOCITY BODY Z, knots) / atg</Macro>
<Macro Name="Y">(A:VELOCITY BODY X, knots) @X sin /</Macro>
<Element>
<Visible>1</Visible>
<Position X="256" Y="256"/>
<Element>
<Rectangle Color="0x00ff00" Width="1" Height="256" Bright="No">
<HeightCode>@Y</HeightCode>
</Rectangle>
<Rotate>
<Value>@X pi +</Value>
</Rotate>
</Element>
</Element>
 
I'm not a user of P3D but I would think that it follows FSX xml so try HeightScript instead of HeightCode.
 
I was wondering if that was an option but as the HeightCode was working I thought it may be something to do with my math instead. Will give it a go though!
 
So I have tried Chris's suggestion and changed to HeightScript. This does not have the desired effect as the line is now permanently fully extended. I have been trying to stick to FS9 Schema with no apparent issues until now so don't think it is an issue with the XML parser in P3D.

I recall reading somewhere in the forum about a gauge or program that was able to detect the number of events being triggered in the simulation and possibly exposing any leaks, but can not currently find it? I am still a relative novice at XML coding but am pretty sure my issue is with either my intent and understanding of RPN script to make the calculation to start with or some 'leaky' code.

Interestingly, whilst the aircraft is stationary and the heightcode script output is effectively zero there is no issue. It is not until I start to move and the velocities increase that the sim crashes.

If there is another way of achieving the desired output (see post 1) I am open to suggestions.
 
Unknown.. maybe try drawing the height code in its own element, then rotate it in a separate element IE
XML:
<!-- Velocity Vector Hover Modes -->
<Macro Name="X">(A:VELOCITY BODY X, knots) (A:VELOCITY BODY Z, knots) / atg</Macro>
<Macro Name="Y">(A:VELOCITY BODY X, knots) @X sin /</Macro>

<Element>
    <!-- PLACEMENT ELEMENT -->
    <Visible>1</Visible>
    <Position X="256" Y="256"/>
        <!-- ROTATE THE NOW DRAWN RECTANGLE ELEMENT -->
        <Element>
                <!-- CREATE THE RECTANGLE ELEMENT W/ HEIGHT -->
                <Element>
                    <Rectangle Color="0x00ff00" Width="1" Height="256" Bright="No">
                        <HeightCode>@Y</HeightCode>
                    </Rectangle>
                </Element>
            <Rotate>
                <Value>@X pi +</Value>
            </Rotate>
        </Element>
</Element>

Roman
 
Thanks for the suggestion Roman but, still not working. Crashes after a few seconds with this particular gauge open.

I am almost certain my issue is with the calculations I am trying to do at Macro "Y". The intention is to use some basic trigonometry to calculate the hypotenuse length (which is then used for the height of the rectangle) from the the angle (calculated by Macro "X") and an already available opposite length (A:Velocity Body X).

The calculations are giving the desired effect in rotating and lengthening the rectangle but just not lasting long before crashing.
 
Some more ideas to throw in the pot.. :stirthepo
Not real good at geometry / trig so..
Do the values calculated go greater than the 256 size given?
Do the values calculated go negative? ( if possible )

Perhaps?
<HeightCode>@Y abs 265 min</HeightCode>

Maybe show the calculated values in a string by themselves to see what is coming from them.
 
Last edited:
Roman you’ve got me looking in the right direction! It was in fact because I was trying to put a negative value into the @Y calculations (you can not input a negative angle for the sin sum to work).

It’s not working fully as intended yet because the rotation only works through 180 degrees instead of 360 which I want. I am going to try and turn my output into degrees instead of radians to see if it has the desired effect.

Thanks again though Roman.
 
Often you have to test for the rotation angle and use two different pieces of code.
 
Thanks everyone for your input.

I have the gauge working as intended albeit with a little jump when it switches from forward to backward flight in the hover.

XML:
<Update Frequency="20">
(A:VELOCITY BODY X, knots) (A:VELOCITY BODY Z, knots) / atg (>L:VarX, radians)
(A:VELOCITY BODY X, knots) (L:VarX, radians) sin / (>L:VarY, number)
</Update>

<Element>
    <Visible>1</Visible>
    <Position X="256" Y="256"/>
        <Element>
            <Element>
                <Rectangle Color="0x00ff00" Width="1" Height="256" Bright="No">
                <HeightCode>(L:VarY, number) abs 256 min</HeightCode>
                </Rectangle>
            </Element>
        <Rotate>
        <Value>(A:VELOCITY BODY Z, knots) 0 &lt; if{ (L:VarX, radians) } els{ (L:VarX, radians) pi + }</Value>
        </Rotate>
        </Element>
</Element>

I suspect the update section could still work in a macro but have not tried it as yet.
 
Last edited:
Change update frequency from 20 to 18 and test if " little jump " has been reduced or eliminated .

Cheers
Karol
 
Thanks Karol. After some further testing it was actually because I was trying to do too much to flip the LVarX through 180 degrees. It gives the desired output on its own!
 
Back
Top