Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Changing Needle BMPs depending on a particular value in XML gauge

Featured Replies

Is it possible to change a needle BMP based on the value of a variable in a XML gauge?

For example lower values needle is green.

warning level needle is yellow

danger level needle is red.

I also want to change the background color of the digital display based on the same values.

I have tried using the case function and using the visible function but I'm obviously doing something wrong because the gauge disappears in the panel when I go to test the gauge.

Anybody have suggestions on how to make this happen?

 

Jonathan

Use the visibility function:

 

<Element>
<Visible>(A:Autopilot Heading Lock,bool)</Visible>
     <Position X="439" Y="0"/>
            <Image Name="AP_HDGON.bmp" />
</Element>

<Element>
<Visible>(A:Autopilot Nav1 Lock,bool)</Visible>
     <Position X="621" Y="0"/>
            <Image Name="AP_NAVON.bmp" />
</Element>


<Element>
<Visible>(A:Autopilot Approach Hold,bool)</Visible>
     <Position X="729" Y="0"/>
            <Image Name="AP_APRON.bmp" />
</Element>

 

You have three elements and only one shows up at a time.

 

If you make any syntax/grammar error in XML, the whole gauge disappears..

which can make it tough to troubleshoot.

 

I usually find a section of code in an existing gauge and carefully modify it, testing at every change.

Bert

Needles aren't static elements, so not certain they can be turned on/off.

 

Try it!  Sample:

<Element id="VOR 1 CYAN">
					<FloatPosition>255.000,249.000</FloatPosition>
					<Visibility>(L:BRG1 Button, number) 1 ==</Visibility>
					<Image Name="mfd_centred_vor_1_bearing_pointer1.bmp">
						<Transparent>True</Transparent>
						<Axis>10.000,152.000</Axis>
						<Bright>True</Bright>
					</Image>
					<Rotation id="Rotation">
						<PointsTo>NORTH</PointsTo>
						<Expression id="Expression">
							<Script>(A:NAV HAS NAV:1, bool) if{
								(A:NAV1 radial, radians) (A:Plane heading degrees gyro, radians) - pi  + } els{ pi 2 / }
							</Script>
						</Expression>
						<Delay id="Delay">
							<DelayValue>180.000</DelayValue>
							<DelayUnits>DEGREES_PER_SECOND</DelayUnits>
						</Delay>
					</Rotation>
				</Element>

Another option entirely is to draw the needle and vary the color..

Bert

  • Author

Thanks guys for the input!

Here is what I've been working on and I thought I'd pursue it as it initially seemed to be heading the right way but on this first example only the first BMP appears and then the needles disappear completely.

 

First Example:

     <Element>
      <Position X="125" Y="125"/>
      <Select>
         <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 35 >=</Value>
          <Case Value="0">
             <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                <Axis X="5" Y="5"/>
             </Image>
          </Case>
          <Case Value="1">
            <Select>
               <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 65 >=</Value>
                  <Case Value="0">
                     <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                        <Axis X="5" Y="5"/>
                     </Image>
                  </Case>
                  <Case Value="1">
                    <Select>
                       <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Value>
                          <Case Value="0">
                             <Image Name="ENG_Needle_Yellow.bmp" PointsTo="East" Bright="Yes">
                                <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                          <Case Value="1">
                             <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                               <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                   </Select>
                  </Case>
            </Select>
          </Case>
      </Select>
      <Rotate>
         <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
         <Failures>
            <SYSTEM_ENGINE Action="0"/>
            <SYSTEM_ELECTRICAL_PANELS Action="0"/>
         </Failures>
         <Nonlinearity>
             <Item Value="0" X="219" Y="125"/>
             <Item Value="100" X="30" Y="125"/>
         </Nonlinearity>
        <Delay DegreesPerSecond="20"/>
      </Rotate>
      </Element>

 

The original piece looked like the following and it worked. As the RPM increased the needle changed colors. But when I wanted to increase the number of colors I thought I could nest them per the first example but that didn't work. Am I overlooking something?

 

Second Example:

                   <Select>
                       <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Value>
                          <Case Value="0">
                             <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                                <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                          <Case Value="1">
                             <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                               <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                   </Select>


 

Try the visibility option and do not nest them.. sometimes you just have to duplicate the section, with a different visibility condition..

 

Keep it simple

Bert

  • Author

I tried this and the only one that is visible is the red.

         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 0 >=</Visability>
                  <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 35 >=</Visability>
                  <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 65 >=</Visability>
                  <Image Name="ENG_Needle_Yellow.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Visability>
                  <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>

Edited by n4gix
Added [Code] tags to the XML script!

  • Author

Bert, thanks a lot! I got it working. Made a mistake in the above code. Here is the final code, Just multiply it however many colors and change the greater than value for the different colors. Voila! It works! Thanks again!

         <Element>
            <Position X="125" Y="125"/>
               <Visible>(A:PROP1 MAX RPM PERCENT, percent) abs 120 >=</Visible>
                  <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>

Edited by n4gix
Added [Code] tags to the XML script!

:rolleyes:

 

If you only change the greater than condition, you may may be displaying several needles on top of each other..  better to define ranges

 

example:   ...120 >=   150 <  and..

Bert

  • Moderator

:rolleyes:

 

If you only change the greater than condition, you may may be displaying several needles on top of each other..  better to define ranges

 

example:   ...120 >=   150 <  and..

Better still, use the "range" function!

 

<Visible>120 150 (A:PROP1 MAX RPM PERCENT, percent) rng</Visible>

Please guys, when posting XML script or C code, use the <> icon in the editor to wrap it into a Code Box. It makes it ever so much easier to read as well as copy/paste. B)

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

BTW, there is a problem in FSX with separate multiple Element sections, each with their own Visible lines.  In some cases the later changes will not display.  In those cases a solution is to use nested Elements, with the Visible line only in the "master" Element.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.