Jump to content
Sign in to follow this  
Jonathan Lueb

Changing Needle BMPs depending on a particular value in XML gauge

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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>


 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

: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

Share this post


Link to post
Share on other sites

: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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...