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

FS2004 Kinda proud of this...

Messages
779
Country
unitedstates
...even though it took way to long and probably looks a bit crude to the pros.

The mission: a new switch for the taxi/landing lights on the default Lear 45.

The goal: taxi lights dependent on gear position. They should only be on when the gear is down.

The code...

Code:
<Gauge Name="3WayLandingLights" Version="1.0">

  <Element>
  <Select>
    <Value>(L:3wayLLswitch,number)</Value>
  <Case Value="0">
  <Image Name="switch_off.bmp"/>
      </Case>
  <Case Value="1">
  <Image Name="switch_mid.bmp"/>
  </Case>
  <Case Value="2">
  <Image Name="switch_on.bmp"/>
  </Case>
  </Select>
  </Element>
   
  <Element>  <!--  Off  -->
     <Select>
  <Value>(L:3wayLLswitch,number) 0 == if{ 0 (&gt;K:LANDING_LIGHTS_SET) (A:LIGHT TAXI,bool) if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } }</Value>
   </Select>     
  </Element>
         
  <Element>  <!-- Taxi  -->
   <Select>
    <Value>(L:3wayLLswitch,number) 1 == if{ 0 (&gt;K:LANDING_LIGHTS_SET) }</Value>
   </Select>     
  </Element>
         
  <Element>  <!-- Land  -->
   <Select>
    <Value>(L:3wayLLswitch,number) 2 == if{ 1 (&gt;K:LANDING_LIGHTS_SET) }</Value>
   </Select>     
  </Element>
         
   <Element>   <!-- Taxi  -->
    <Select>
     <Value>(L:3wayLLswitch,number) 1 == if{ (A:GEAR POSITION,percent) 75 >= if{ (A:LIGHT TAXI,bool) 0 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } els{  (A:LIGHT TAXI,bool) 1 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } }</Value>
    </Select>     
   </Element>
   
   <Element>   <!--  Land  -->
    <Select>
     <Value>(L:3wayLLswitch,number) 2 == if{ (A:GEAR POSITION,percent) 75 >= if{ (A:LIGHT TAXI,bool) 0 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } els{  (A:LIGHT TAXI,bool) 1 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } }</Value>
    </Select>     
   </Element>         
 
  <Mouse>
     <Tooltip>Taxi/Landing Lights</Tooltip>
     
   <Area Left="0" Top="0" Width="34" Height="21">   
     <Cursor Type="UpArrow"/>
     <Click>(L:3wayLLswitch,number) 2 &lt; if{ (L:3wayLLswitch,number) 1 + d (&gt;L:3wayLLswitch,number) }</Click>
   </Area>

   <Area Left="0" Top="22" Width="34" Height="21">
     <Cursor Type="DownArrow"/>
     <Click>(L:3wayLLswitch,number) 0 &gt; if{ (L:3wayLLswitch,number) 1 - d (&gt;L:3wayLLswitch,number) }</Click>
   </Area>
   
  </Mouse>
</Gauge>

Any suggestions to clean this up are appreciated.

cheers,
Lane
(still an XML newb, after all these years)
 

tgibson

Resource contributor
Messages
10,171
Country
us-california
Hi,

Only one big problem I see. When the 3wayLLswitch variable is set to a certain number, your code will be sending K: commands to the sim 18 times a second (the rate that gauge code is evaluated). This will swamp the sim with commands, and make multiple key commands impossible (like opening a second door, selecting other than engine 1, etc.). Too many of this and your frame rate will probably suffer too.

A logical solution is to move all the K: commands into the Mouse section which will only be run once, when you click the mouse.

One other thing that you can do to streamline things is instead of using 3 separate bitmaps for the knob, use only one and then a Rotate command to rotate it to the right position in each case. But separate bitmaps work too, no big problem.

Hope this helps,
 
Messages
779
Country
unitedstates
Thanks for the advice Tom, much appreciated.

I will look at the K: commands.

As for the bitmaps, I think you can see why a rotate will not work, hehe...
Capture.JPG


cheers,
Lane
 
Messages
779
Country
unitedstates
OK, progress has been made.

I have eliminated the spurious K: commands when the switch is in the off position, which it will be most of the time.

The challenge with moving all of the K: events to the mouse section is that doing so limits the (A:GEAR POSITION,percent) poll to once, when the gauge is clicked. I need it to continue to poll after the mouse click.

I think I can limit the polling to only happen when the gear is in transit, which should help.

Since it is only a light switch, limiting the update frequency to 1/sec will probably be OK too. (Something I did during testing, when all I could get it to do is toggle the taxi lights 18/sec, thought I was gonna have a seizure.)

For now, Easter dinner beckons, so Happy Easter to those who celebrate it and Happy Sunday to those that don't.

cheers,
Lane
 
Messages
76
Country
netherlands
I would use an L:var (bool) to store the desired state of the taxilight and use the mouse section only to set that L:var on and off.
Then the code inside an element that is evaluated each frame compares the desired state to the actual state and if they are not the same toggles the taxilight:
(A:gear position, percent) 50 > (L:taxilight_set, bool) && (A:taxilight, bool) == ! if{ (>K:toggle taxilight) }
The code will run 18 times/sec but the command is only sent when the actual state and desired state do not match.

You can also use one <Element><Select><Value>... structure for all code.
 
Messages
779
Country
unitedstates
OK, changing...
Code:
(L:3wayLLswitch,number) 1 == if{ 0 (&gt;K:LANDING_LIGHTS_SET) }

...to...
Code:
(L:3wayLLswitch,number) 1 == if{ (A:LIGHT LANDING, bool) if{ 0 (&gt;K:LANDING_LIGHTS_SET) } }
...took care of the continuous K:events

Hi Jeroen, thanks for commenting.
I would use an L:var (bool) to store the desired state of the taxilight and use the mouse section only to set that L:var on and off.
Then the code inside an element that is evaluated each frame compares the desired state to the actual state and if they are not the same toggles the taxilight:
(A:gear position, percent) 50 > (L:taxilight_set, bool) && (A:taxilight, bool) == ! if{ (>K:toggle taxilight) }
The code will run 18 times/sec but the command is only sent when the actual state and desired state do not match.

Sorry, Jeroen, I cannot see how that is any different than...
Code:
(L:3wayLLswitch,number) 1 == if{ (A:GEAR POSITION,percent) 75 >= if{ (A:LIGHT TAXI,bool) 0 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } els{  (A:LIGHT TAXI,bool) 1 == if{ (&gt;K:TOGGLE_TAXI_LIGHTS) } } }
If L:Var = 1 then

if gear more than 75% extended then

if taxi lights are off then

toggle taxi lights.

If any of those answers are false the code stops before the K: event.

You used ands, I used ifs, does the sim care?

You can also use one <Element><Select><Value>... structure for all code.

Yeah, I split it up like that to make it easier for me to read while testing.

This gauge went through several iterations before I figured out one that would work and I wanted to make sure that fixing one aspect of the gauge didn't break another.

I added <Update Frequency="4"/> to lessen the A:Var polling, I tried <Update Frequency="1"/> and noticed an occasional, noticeable delay in switch response.

Thanks for all the help so far.

cheers,
Lane
 

tgibson

Resource contributor
Messages
10,171
Country
us-california
Yes, your code does the same thing, but:

1. It's harder to read
2. It's longer.
 

n4gix

Resource contributor
Messages
11,661
Country
unitedstates
This:
Code:
(L:3wayLLswitch,number) 1 == if{ (A:LIGHT LANDING, bool) if{ 0 (&gt;K:LANDING_LIGHTS_SET) } }

is the same as this:
Code:
(L:3wayLLswitch,number) 1 == (A:LIGHT LANDING, bool) and if{ 0 (&gt;K:LANDING_LIGHTS_SET) }
 
Messages
779
Country
unitedstates
This:
Code:
(L:3wayLLswitch,number) 1 == if{ (A:LIGHT LANDING, bool) if{ 0 (&gt;K:LANDING_LIGHTS_SET) } }

is the same as this:
Code:
(L:3wayLLswitch,number) 1 == (A:LIGHT LANDING, bool) and if{ 0 (&gt;K:LANDING_LIGHTS_SET) }
OK, I can see that.

Is there any advantage to one method over the other? Other than your method has one less character?
 
Messages
669
Country
australia
Pick the method that is more readable to you. Not only now but in 6 months down the track when you've forgotten what the code was trying to do.

If you were doing a thousand of these every frame then you would need to worry about whichever was quicker (and as we are talking about XML then it's anyone's guess as to which is the quicker method) but if you're only doing a handful of these then readability (and therefore debugability) is more important.

Of course, with multiple if statements keeping count of the curly brackets can start to become a real headache.

Personally when using if statements I like to neatly space them out over multiple lines as one continuous line of nested if statements is about as unreadable as you can get.
 
Top