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

XML Guage Question

krispy1001

Resource contributor
Messages
707
Country
unitedstates
Hi Everyone!

I am new to xml programming, I am a Java programmer.

I went through the two tutorials in the "Panels and Gauges SDK" and made the fuel pressure, and stop watch gauges. I have also looked at a lot of default gauges in FSX.

I would like to make an xml button that when pushed, would lock your aircraft's altitude at that altitude and maintain it stationary. I have read through the sdk and I found that there is an update command that you can use to keep checking to see if the variable's value has changed and then you can make changes with code to keep the value at what you want it to be. I have also checked that the sim variable that I want to change can be wrote to. The variable is "PLANE ALTITUDE"

Just to do a simple testing to see if I could write a value to PLANE ALTITUDE I tried the below code.

<Gauge Name="Altitude Hold Switch" Version="1.0">
<Element>
<Select>
<Value>(A:Autopilot master,bool)</Value>
<Failures>
<SYSTEM_ELECTRICAL_PANELS Action="0" />
</Failures>
<Case Value="0">
<Image Name="AP_Up.bmp" />
</Case>
<Case Value="1">
<Image Name="AP_Down.bmp" />
<Value>(A: PLANE ALTITUDE,Feet) 6000 =</Value>
</Case>
</Select>
</Element>
<Mouse>
<Help ID="HELPID_GAUGE_AUTOPILOT_MASTER" />
<Tooltip ID="TOOLTIPTEXT_AUTOPILOT_MASTER" />
<Area Left="2" Top="3" Right="14" Bottom="14">
<Cursor Type="Hand" />
<Click Kind="LeftSingle">(&gt;K:AP_MASTER)</Click>
</Area>
</Mouse>

+++I had to add a space in the PLANE ALTITUDE code so that a smiley face would not show up.

The code did nothing!

Any suggestions on any tutorials on how to write to a sim variable?

Thanks, Kris :)
 
Last edited:
First... XML can't write to sim vars... that's a SimConnect functionality. I believe there is a "workaround" using XMLTools, but I'm no expert. However, since there is already an altitude hold autopilot.. that does what you're wanting... what are you doing, exactly?
 
This from the events section of the SDK:

Freezing position


KEY_FREEZE_LATITUDE_LONGITUDE_TOGGLE FREEZE_LATITUDE_LONGITUDE_TOGGLE Turns the freezing of the lat/lon position of the aircraft (either user or AI controlled) on or off. If this key event is set, it means that the latitude and longitude of the aircraft are not being controlled by ESP, so enabling, for example, a SimConnect client to control the position of the aircraft. This can also apply to altitude and attitude. Refer to the simulation variables:
IS LATITUDE LONGITUDE FREEZE ON,
IS ALTITUDE FREEZE ON, and
IS ATTITUDE FREEZE ON
Refer also to the SimConnect_AIReleaseControl function. Shared Cockpit
KEY_FREEZE_LATITUDE_LONGITUDE_SET FREEZE_LATITUDE_LONGITUDE_SET Freezes the lat/lon position of the aircraft. Shared Cockpit
KEY_FREEZE_ALTITUDE_TOGGLE FREEZE_ALTITUDE_TOGGLE Turns the freezing of the altitude of the aircraft on or off. Shared Cockpit
KEY_FREEZE_ALTITUDE_SET FREEZE_ALTITUDE_SET Freezes the altitude of the aircraft.. Shared Cockpit
KEY_FREEZE_ATTITUDE_TOGGLE FREEZE_ATTITUDE_TOGGLE Turns the freezing of the attitude (pitch, bank and heading) of the aircraft on or off. Shared Cockpit
KEY_FREEZE_ATTITUDE_SET FREEZE_ATTITUDE_SET Freezes the attitude (pitch, bank and heading) of the aircraft. Shared Cockpit
 
First... XML can't write to sim vars... that's a SimConnect functionality. I believe there is a "workaround" using XMLTools, but I'm no expert. However, since there is already an altitude hold autopilot.. that does what you're wanting... what are you doing, exactly?
Hi WarpD!
Thanks for your information. I want to setup a hover mode for an aircraft, and I wanted to do it myself. I like learning new things.
If learning to use sim-connect is the only way, than I will start learning sim-connect.

Thanks, Kris

This from the events section of the SDK:

Freezing position


KEY_FREEZE_LATITUDE_LONGITUDE_TOGGLE FREEZE_LATITUDE_LONGITUDE_TOGGLE Turns the freezing of the lat/lon position of the aircraft (either user or AI controlled) on or off. If this key event is set, it means that the latitude and longitude of the aircraft are not being controlled by ESP, so enabling, for example, a SimConnect client to control the position of the aircraft. This can also apply to altitude and attitude. Refer to the simulation variables:
IS LATITUDE LONGITUDE FREEZE ON,
IS ALTITUDE FREEZE ON, and
IS ATTITUDE FREEZE ON
Refer also to the SimConnect_AIReleaseControl function. Shared Cockpit
KEY_FREEZE_LATITUDE_LONGITUDE_SET FREEZE_LATITUDE_LONGITUDE_SET Freezes the lat/lon position of the aircraft. Shared Cockpit
KEY_FREEZE_ALTITUDE_TOGGLE FREEZE_ALTITUDE_TOGGLE Turns the freezing of the altitude of the aircraft on or off. Shared Cockpit
KEY_FREEZE_ALTITUDE_SET FREEZE_ALTITUDE_SET Freezes the altitude of the aircraft.. Shared Cockpit
KEY_FREEZE_ATTITUDE_TOGGLE FREEZE_ATTITUDE_TOGGLE Turns the freezing of the attitude (pitch, bank and heading) of the aircraft on or off. Shared Cockpit
KEY_FREEZE_ATTITUDE_SET FREEZE_ATTITUDE_SET Freezes the attitude (pitch, bank and heading) of the aircraft. Shared Cockpit

Hi Ddawson!

Thank you very much for the information! That may be what I need. I will search for "KEY_FREEZE_ALTITUDE_SET" in the Gauge and Panel SDK. Thank you very much for the information.

Kris :-)
 
Ok, here is my first attempt to write my hover xml code. I am getting an error and I do not see one. Can anyone spot what I am doing wrong? Thanks, Kris :-)

<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">
<Descr>AceXML Document</Descr>
<Filename>Hover.xml</Filename>
<SimGauge.Gauge id="Gauge" ArtDirectory="C:\Kris_Work\FSX_Gauges\UV4Gauges">
<FloatPosition>0.000,0.000</FloatPosition>
<Image id="Hover image" Name="hover.bmp">
<Transparent>True</Transparent>
</Image>
<Element id="Element">
<FloatPosition>50.000,35.000</FloatPosition>
<Rectangle id="Rectangle">
<LineWidth>1</LineWidth>
<Width>12</Width>
<Height>10</Height>
<LineColor>silver</LineColor>
<FillColor>silver</FillColor>
</Rectangle>
</Element>
<MouseArea id="On/Off">
<FloatPosition>41.000,1.000</FloatPosition>
<Size>12,10</Size>
<CursorType>Hand</CursorType>
<MouseClick id="MouseClick">
<Script>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 1 (&gt;L:STSTP Pressed,bool) (L:Running,bool) ! (&gt;L:Running,bool) } (L:Running, bool) ! if{ (A:FREEZE_ALTITUDE_TOGGLE, bool)1= (&gt;L:KEY_FREEZE_ALTITUDE_SET,bool)1= (A:KEY_FREEZE_ATTITUDE_TOGGLE,bool)1= (A:KEY_FREEZE_ATTITUDE_SET,bool)1= } (M:Event) &apos;LeftRelease&apos; scmp 0 == if{ 0 (&gt;L:STSTP Pressed,bool) (A:FREEZE_ALTITUDE_TOGGLE, bool)0= (&gt;L:KEY_FREEZE_ALTITUDE_SET,bool)0= (A:KEY_FREEZE_ATTITUDE_TOGGLE,bool)0= (A:KEY_FREEZE_ATTITUDE_SET,bool)0=}</Script>
<ClickType>LeftSingle+LeftRelease</ClickType>
</MouseClick>
</MouseArea>
</SimGauge.Gauge>
</SimBase.Document>
 
Please put XML script in a Code Box to make it easier to read!
qrWUi.png

I've taken the liberty to copy/paste/format your sample mouse code, since that is without question where you've got the most errors. I'll leave it to others to deal with those... :cool:

Code:
<MouseClick id="MouseClick">
    <ClickType>LeftSingle+LeftRelease</ClickType>
    <Script>
        (M:Event) 'LeftSingle' scmp 0 ==
        if{ 1 (>L:STSTP Pressed,bool) (L:Running,bool) ! (>L:Running,bool) }
       
        (L:Running, bool) !
        if{
            (A:FREEZE_ALTITUDE_TOGGLE, bool)1=
            (&gt;L:KEY_FREEZE_ALTITUDE_SET,bool)1=
            (A:KEY_FREEZE_ATTITUDE_TOGGLE,bool)1=
            (A:KEY_FREEZE_ATTITUDE_SET,bool)1=
        }
           
        (M:Event) 'LeftRelease'scmp 0 ==
        if{
            0 (>L:STSTP Pressed,bool)
            (A:FREEZE_ALTITUDE_TOGGLE, bool)0= (>L:KEY_FREEZE_ALTITUDE_SET,bool)0=
            (A:KEY_FREEZE_ATTITUDE_TOGGLE,bool)0=
            (A:KEY_FREEZE_ATTITUDE_SET,bool)0=
        }
    </Script>
</MouseClick>
 
Last edited:
You need to discriminate between read (A:) and command (K:) variables and add more spaces.
Boolean variable evaluation may be expressed in a truncated form ('(A:[variable name], bool) !' meaning "if value is not one").
EventIDs (K: variables) do not require a unit and "KEY_" prefix (the latter only when called from a XML gauge). Also, Toggle type EventID do not require a value.

And you're overcomplicating things. This is what I think you want to do in simpler terms:

Code:
<ClickType>LeftSingle</ClickType>
<Script>(A:IS ALTITUDE FREEZE ON, bool) ! if{ (>K:FREEZE_ATTITUDE_TOGGLE) }
(A:IS ATTITUDE FREEZE ON, bool) ! if{ (>K:FREEZE_ATTITUDE_TOGGLE) }
(A:IS LATITUDE LONGITUDE FREEZE ON, bool) ! if{ (>K:FREEZE_LATITUDE_LONGITUDE_TOGGLE) }
</Script>

Or even shorter:
Code:
<ClickType>LeftSingle</ClickType>
<Script>1 (>K:FREEZE_LATITUDE_LONGITUDE_SET)
1 (>K:FREEZE_ATTITUDE_SET)
1 (>K:FREEZE_ALTITUDE_SET)
</Script>

But you might want to turn this into a toggle button, so:
Code:
<ClickType>LeftSingle</ClickType>
<Script>(A:IS ALTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_LATITUDE_LONGITUDE_SET) } els{ 0 (>K:FREEZE_LATITUDE_LONGITUDE_SET) }
(A:IS ATTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ATTITUDE_SET) } els{ 0 (>K:FREEZE_ATTITUDE_SET) }
(A:IS LATITUDE LONGITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ALTITUDE_SET) } els{ 0 (>K:FREEZE_ALTITUDE_SET) }
</Script>
 
Last edited:
Please put XML script in a Code Box to make it easier to read!

Hi Mr. Bill!

Yes! I will start putting my code in a Code box. Thank you very much Mr. Bill for you information.


You need to discriminate between read (A:) and command (K:) variables and add more spaces.
Boolean variable evaluation may be expressed in a truncated form ('(A:[variable name], bool) !' meaning "if value is not one").
EventIDs (K: variables) do not require a unit and "KEY_" prefix (the latter only when called from a XML gauge). Also, Toggle type EventID do not require a value.

And you're overcomplicating things. This is what I think you want to do in simpler terms:

Hi Mr. Heretic!

Thank you very much for explaining what I am doing wrong. It is going to take me some time to get the flow of xml and reverse polish notation. I will examine the code examples you gave me and try to follow what it is doing.

Thank you very much Mr. Heritic, and Mr. Bill.

I will let you guys know my progress.

Kris :-)
 
Hi Guys!
Here is my second attempt at writing XML code for hover. I am getting an error that FSX can not read my gauge. I do not see anything that I have wrong. It would be nice if FSX would tell you if it is a syntax error.

Can anyone see what my error could be. Thank you very much, Kris :-)
Code:
<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">
    <Descr>AceXML Document</Descr>
    <Filename>Hover.xml</Filename>
    <SimGauge.Gauge id="Gauge" ArtDirectory="C:\Kris_Work\FSX_Gauges\UV4Gauges">
        <FloatPosition>0.000,0.000</FloatPosition>
        <Image id="Hover image" Name="hover.bmp">
            <Transparent>True</Transparent>
        </Image>

    <Element id="Element">
        <FloatPosition>0.0,0.0</FloatPosition>
            <Rectangle id="Rectangle">
                <LineWidth>1</LineWidth>
                <Width>50</Width>
                <Height>35</Height>
                <LineColor>silver</LineColor>
                <FillColor>silver</FillColor>
            </Rectangle>
        <Select>
                <Value>(A:IS ALTITUDE FREEZE ON,bool)</Value>
                <Failures>
                    <SYSTEM_ELECTRICAL_PANELS Action="0" />
                </Failures>
                <Case Value="0">
                    <Image Name="AP_Up.bmp" />
                </Case>
                <Case Value="1">
                    <Image Name="AP_Down.bmp" />
            </Case>
            </Select>
    </Element>
    <MouseArea id="On/Off">
            <FloatPosition>0.000,0.000</FloatPosition>
            <Size>50,35</Size>
            <CursorType>Hand</CursorType>
            <MouseClick id="MouseClick">
        <ClickType>LeftSingle</ClickType>
        <Script>
            (A:IS ALTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_LATITUDE_LONGITUDE_SET) } els{ 0 (>K:FREEZE_LATITUDE_LONGITUDE_SET) }
            (A:IS ATTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ATTITUDE_SET) } els{ 0 (>K:FREEZE_ATTITUDE_SET) }
            (A:IS LATITUDE LONGITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ALTITUDE_SET) } els{ 0 (>K:FREEZE_ALTITUDE_SET) }
        </Script>
        </MouseClick>
    </MouseArea>

    </SimGauge.Gauge>
</SimBase.Document>
 
Hi Everyone!

Ok, I found my problem. I had an syntax error in my code. The code works good now. The next thing I am going to work on is a if then statement that only allows this code to work if the aircraft is below a certain speed. Below is the XML code that is working for me. It is a crude way to get an aircraft to hover, but it works, and I think with some re-fining it will turn out good.

Thank you very much, Mr. Heretic, and Mr. Bill!!!!!!!!!!!!!!!

Code:
<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">
    <Descr>AceXML Document</Descr>
    <Filename>Hover.xml</Filename>
    <SimGauge.Gauge id="Gauge" ArtDirectory="C:\Kris_Work\FSX_Gauges\UV4Gauges">
        <FloatPosition>0.000,0.000</FloatPosition>
        <Image id="Hover image" Name="hover.bmp">
            <Transparent>True</Transparent>
        </Image>
        <Element id="Element">
            <FloatPosition>50.000,35.000</FloatPosition>
            <Rectangle id="Rectangle">
                <LineWidth>1</LineWidth>
                <Width>49</Width>
                <Height>34</Height>
                <LineColor>silver</LineColor>
                <FillColor>silver</FillColor>
            </Rectangle>
        </Element>
        <MouseArea id="On/Off">
            <FloatPosition>0.000,0.000</FloatPosition>
            <Size>49,34</Size>
            <CursorType>Hand</CursorType>
            <MouseClick id="MouseClick">
        <ClickType>LeftSingle</ClickType>
        <Script>(A:IS ALTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_LATITUDE_LONGITUDE_SET) } els{ 0 (>K:FREEZE_LATITUDE_LONGITUDE_SET) }
(A:IS ATTITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ATTITUDE_SET) } els{ 0 (>K:FREEZE_ATTITUDE_SET) }
(A:IS LATITUDE LONGITUDE FREEZE ON, bool) ! if{ 1 (>K:FREEZE_ALTITUDE_SET) } els{ 0 (>K:FREEZE_ALTITUDE_SET) }
</Script>
               
            </MouseClick>
        </MouseArea>
    </SimGauge.Gauge>
</SimBase.Document>

Thanks, Kris
 
Code:
<Click>(L:AP ALT HOLD,number) 0 == if{ 1 (&gt;L:AP ALT HOLD,number) 0 (&gt;L:AP IAS HOLD,number) 0 (&gt;L:AP MACH HOLD,number) 0 (&gt;K:AP_ALT_HOLD_ON) (L:precision_indicated_altitude, feet) (&gt;K:AP_ALT_VAR_SET_ENGLISH) 0 (&gt;K:AP_VS_VAR_SET_ENGLISH) } els{ 0 (&gt;L:AP ALT HOLD,number) 1 (&gt;K:AP_ALT_HOLD_ON) 0 (&gt;K:AP_ALT_VAR_SET_ENGLISH) (A:Vertical speed,feet per minute) (&gt;K:AP_VS_VAR_SET_ENGLISH) 1 (>L:Sound_AP click,enum) }</Click>
This is a snippet from the AP code for the VC10 which has an "old school" autopilot with Altitude lock. The (L: Precision_indicated_altitude, feet) is no more than a substitute for the A var because I have had to recode the precision altimeter and the standby as separate instruments. There is also a datum adjust knob which feeds into this but is not shown here.
 
Back
Top