Low Fuel Warning Light Output for X-Plane 12
Re: Low Fuel Warning Light Output for X-Plane 12
SimPassion, thanks so much for explaining the use of the parameters in the function. In FS2020 the code does respond, but only runs once. It does not respond to a change in the fuel level. If I press RUN in the Create/Edit tab, the code will run and display the correct light status. How do I make the program run on a continuous basis?
-
- Posts: 5346
- Joined: Thu Jul 27, 2017 12:22 am
Re: Low Fuel Warning Light Output for X-Plane 12
Hi @Voyager, I haven't added any change, just corrected issue, you just have to add the "elseif" part, or even simpler "else", to make the led light offVoyager wrote: ↑Wed Apr 26, 2023 1:20 am SimPassion, thanks so much for explaining the use of the parameters in the function. In FS2020 the code does respond, but only runs once. It does not respond to a change in the fuel level. If I press RUN in the Create/Edit tab, the code will run and display the correct light status. How do I make the program run on a continuous basis?
Try again and come here on issue please
Re: Low Fuel Warning Light Output for X-Plane 12
SimPassion, thanks again. I added an "else" clause, and now the program runs. Unfortunately, it only responded to the level in the right tank, even though the Viewer clearly showed the left tank level changing as well. I therefore modified the program from (left + right) to Total and now the program runs correctly. I posted the latest version of the program above.
Code: Select all
arbitrary_low_qty = 10
prop_tank = user_prop_add_enum("All", "Left,Right,All", "All", "For FS2020 choose the tank")
low_fuel_light = hw_output_add("Low fuel light", false)
prop_tank = user_prop_add_enum("All", "Left,Right,All", "All", "For FS2020 choose the tank")
left_low_fuel_light = hw_output_add("LEFT Low fuel light", false)
right_low_fuel_light = hw_output_add("RIGHT Low fuel light", false)
all_low_fuel_light = hw_output_add("ALL [BOTH] Low fuel light", false)
xpl_dataref_subscribe(
"sim/cockpit2/fuel/fuel_quantity", "FLOAT[9]",
"sim/cockpit2/electrical/bus_volts", "FLOAT[6]",
function(fuel_qty, bus_volts)
if user_prop_get(prop_tank) == "Left" then
hw_output_set(left_low_fuel_light, fuel_qty[1] < arbitrary_low_qty and bus_volts[1] >= 8)
elseif user_prop_get(prop_tank) == "Right" then
hw_output_set(right_low_fuel_light, fuel_qty[2] < arbitrary_low_qty and bus_volts[1] >= 8)
elseif user_prop_get(prop_tank) == "All" then
hw_output_set(left_low_fuel_light, fuel_qty[1] < arbitrary_low_qty and bus_volts[1] >= 8)
hw_output_set(right_low_fuel_light, fuel_qty[2] < arbitrary_low_qty and bus_volts[1] >= 8)
hw_output_set(all_low_fuel_light, fuel_qty[1] < arbitrary_low_qty and fuel_qty[2] < arbitrary_low_qty and bus_volts[1] >= 8)
end
end)
fs2020_variable_subscribe("FUEL TOTAL QUANTITY", "Gallons", -- 4 x variables subscribed expected to be forwarded to the inline function
"ELECTRICAL MAIN BUS VOLTAGE", "Volts",
function(all, bus_volts) -- 4 x parameters required
if all<7.5 and bus_volts >8 then -- fixed unexpected duplicate parenthesis after the if !! ;-)
hw_output_set(low_fuel_light,true)else -- added ",true" which was missing in the reported script extract
hw_output_set (low_fuel_light, false) -- resets light to off
end
end)