- Messages
- 240
- Country

In the process of coding the overhead panel of the Saab I reached the lights panel and with it one of FSX's most unflexible systems.
In FS all lights are usually tied to the default battery. The aircraft.cfg offers to assign the lights to different buses, but they are way too few - at least for simulating a more complex aircraft.
Therefore, I came up with my own electrical system and simulated all the buses and relays with L:Vars.
Now I got to the point where I connected all the cables and plugs...
The easy step is to write a logic, that toggles the lights on/off depending on the VC switch position and your custom bus voltages.
The problem arises when you want to make it "keyboard-input-safe".
-> When the user toggles the landing lights via keyboard (ie Ctrl+L), the Sim doesn't know whether
a) the event came from my logic, which turned the lights on, because the bus voltage just got high enough
- or -
b) the user didn't want to use his mouse to click the VC-switch and simply toggled the VC-switch with the keyboard.
That's an important difference, but in both cases the Sim will just toggle the lights, because it sensed the event.
The later posts of this thread explain the problem far better than my horrible description could ever do.
I ended up with this:
(The VC-switch is animated by (L:LIGHT Landing, bool) )
The magic lays in the key trap itself, which senses if the command comes from the logic or from the user.
...and fully adapted to the electric system:
Conclusion:
- User can toggle the VC-switch via keyboard commands and via mouse
- lights will only turn on when the corresponding bus is powered and the VC-switch is on
- keyboard commands won't work from external view (works perfectly with XMLTools though)
- you need one extra L:Var for every switch (dunno if this works with G:Vars...)
- coding effort is still manageable
I'm pretty happy with the results. (*)
Most important advantage is that you can fully customize the conditions when the lights are on and when not without worrying about the key commands.
I'm sorry, if this has already been known, I just thought it might be helpful for some developers.
(*) Follow up question: [SOLVED]
The key traps only work in the VC, which is realistic for me. But is there any way to make them work from the external as well?
Maybe putting the key trap code in the modeldef and attaching it to a poly in the VC?
In FS all lights are usually tied to the default battery. The aircraft.cfg offers to assign the lights to different buses, but they are way too few - at least for simulating a more complex aircraft.
Therefore, I came up with my own electrical system and simulated all the buses and relays with L:Vars.
Now I got to the point where I connected all the cables and plugs...
The easy step is to write a logic, that toggles the lights on/off depending on the VC switch position and your custom bus voltages.
The problem arises when you want to make it "keyboard-input-safe".
-> When the user toggles the landing lights via keyboard (ie Ctrl+L), the Sim doesn't know whether
a) the event came from my logic, which turned the lights on, because the bus voltage just got high enough
- or -
b) the user didn't want to use his mouse to click the VC-switch and simply toggled the VC-switch with the keyboard.
That's an important difference, but in both cases the Sim will just toggle the lights, because it sensed the event.
The later posts of this thread explain the problem far better than my horrible description could ever do.
I ended up with this:
Code:
<Element Name="Lights"><Select><Value>
0 (>L:switch_changed_LL,bool)
(L:LIGHT Landing, bool) (L:L_Main_Bus, number) 18 > (L:R_Main_Bus, number) 18 > or and (A:LIGHT Landing, bool) !=
if{ 1 (>L:switch_changed_LL,bool) (>K:LANDING_LIGHTS_TOGGLE) }
</Value></Select></Element>
<Keys>
<On Event="LANDING_LIGHTS_TOGGLE">
(L:switch_changed_LL,bool)
if{ 0 (>L:switch_changed_LL,bool) }
els{ (L:LIGHT Landing, bool) ! (>L:LIGHT Landing, bool) }
</On>
</Keys>
(The VC-switch is animated by (L:LIGHT Landing, bool) )
The magic lays in the key trap itself, which senses if the command comes from the logic or from the user.
...and fully adapted to the electric system:
Code:
<Element Name="Lights">
<Select><Value>
0 (>L:switch_changed_LL,bool)
(L:LIGHT Landing, bool) (L:L_Main_Bus, number) 18 > (L:R_Main_Bus, number) 18 > or * (A:LIGHT Landing, bool) != if{ 1 (>L:switch_changed_LL,bool) (>K:LANDING_LIGHTS_TOGGLE) }
0 (>L:switch_changed_strobes,bool)
(L:LIGHT Strobes, bool) (L:R_Main_Bus, number) 18 > * (A:LIGHT Strobe, bool) != if{ 1 (>L:switch_changed_strobes,bool) (>K:STROBES_TOGGLE) }
0 (>L:switch_changed_nav,bool)
(L:LIGHT Nav, bool) (L:L_Main_Bus, number) 18 > (L:R_Main_Bus, number) 18 > or * (A:LIGHT Nav, bool) != if{ 1 (>L:switch_changed_nav,bool) (>K:TOGGLE_NAV_LIGHTS) }
0 (>L:switch_changed_wing,bool)
(L:LIGHT Wing, bool) (L:R_Main_Bus, number) 18 > * (A:LIGHT Wing, bool) != if{ 1 (>L:switch_changed_wing,bool) (>K:TOGGLE_Wing_LIGHTS) }
0 (>L:switch_changed_logo,bool)
(L:LIGHT Logo, bool) (L:R_Main_Start_Bus, number) 18 > * (A:LIGHT Logo, bool) != if{ 1 (>L:switch_changed_logo,bool) (>K:TOGGLE_Logo_LIGHTS) }
0 (>L:switch_changed_beacon,bool)
(L:LIGHT Beacon, bool) (L:L_Bat_Bus, number) 18 > * (A:LIGHT Beacon, bool) != if{ 1 (>L:switch_changed_beacon,bool) (>K:TOGGLE_BEACON_LIGHTS) }
0 (>L:switch_changed_taxi,bool)
(L:LIGHT Taxi, bool) (L:L_Bat_Bus, number) 18 > * (A:LIGHT Taxi, bool) != if{ 1 (>L:switch_changed_taxi,bool) (>K:TOGGLE_Taxi_LIGHTS) }
</Value></Select>
</Element>
<Keys>
<On Event="LANDING_LIGHTS_TOGGLE">
(L:switch_changed_LL,bool) if{ 0 (>L:switch_changed_LL,bool) } els{ (L:LIGHT Landing, bool) ! (>L:LIGHT Landing, bool) }
</On>
<On Event="STROBES_TOGGLE">
(L:switch_changed_strobes,bool) if{ 0 (>L:switch_changed_strobes,bool) } els{ (L:LIGHT STROBES, bool) ! (>L:LIGHT STROBES, bool) }
</On>
<On Event="TOGGLE_NAV_LIGHTS">
(L:switch_changed_nav,bool) if{ 0 (>L:switch_changed_nav,bool) } els{ (L:LIGHT NAV, bool) ! (>L:LIGHT NAV, bool) }
</On>
<On Event="TOGGLE_WING_LIGHTS">
(L:switch_changed_wing,bool) if{ 0 (>L:switch_changed_wing,bool) } els{ (L:LIGHT WING, bool) ! (>L:LIGHT WING, bool) }
</On>
<On Event="TOGGLE_LOGO_LIGHTS">
(L:switch_changed_logo,bool) if{ 0 (>L:switch_changed_logo,bool) } els{ (L:LIGHT LOGO, bool) ! (>L:LIGHT LOGO, bool) }
</On>
<On Event="TOGGLE_BEACON_LIGHTS">
(L:switch_changed_beacon,bool) if{ 0 (>L:switch_changed_beacon,bool) } els{ (L:LIGHT BEACON, bool) ! (>L:LIGHT BEACON, bool) }
</On>
<On Event="TOGGLE_TAXI_LIGHTS">
(L:switch_changed_taxi,bool) if{ 0 (>L:switch_changed_taxi,bool) } els{ (L:LIGHT TAXI, bool) ! (>L:LIGHT TAXI, bool) }
</On>
<On Event="ALL_LIGHTS_TOGGLE">
(L:LIGHT TAXI, bool) ! (>L:LIGHT TAXI, bool)
(L:LIGHT BEACON, bool) ! (>L:LIGHT BEACON, bool)
(L:LIGHT LOGO, bool) ! (>L:LIGHT LOGO, bool)
(L:LIGHT WING, bool) ! (>L:LIGHT WING, bool)
(L:LIGHT NAV, bool) ! (>L:LIGHT NAV, bool)
(L:LIGHT STROBE, bool) ! (>L:LIGHT STROBE, bool)
(L:LIGHT Landing, bool) ! (>L:LIGHT Landing, bool)
</On>
</Keys>
Conclusion:
- User can toggle the VC-switch via keyboard commands and via mouse
- lights will only turn on when the corresponding bus is powered and the VC-switch is on
- keyboard commands won't work from external view (works perfectly with XMLTools though)
- you need one extra L:Var for every switch (dunno if this works with G:Vars...)
- coding effort is still manageable
I'm pretty happy with the results. (*)
Most important advantage is that you can fully customize the conditions when the lights are on and when not without worrying about the key commands.
I'm sorry, if this has already been known, I just thought it might be helpful for some developers.
(*) Follow up question: [SOLVED]
The key traps only work in the VC, which is realistic for me. But is there any way to make them work from the external as well?
Maybe putting the key trap code in the modeldef and attaching it to a poly in the VC?
Last edited:

