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

Selecting an Engine in Fuel Selector

Hello Gentlemen,

I am trying to program a set of Gauges for a P-38 Lightning using the FS2000 SDK.

Each Engine has its own Fuel Selector.
My issue is that I need to be able to select an Engine for which the Fuel Tank selection applies.
So far my attempts at various methods have not worked. The Fuel Tank selection is done but applies to both Engines.

Any idea what the proper process would be to make this work?

A second question is how to select multiple Fuel Tanks at one time.
This is needed for the Ki 43 Hayabusa which selects Left and Right pairs of Wing Tanks to use simultaneously.

Thanks in Advance.
- Ivan.


Resource contributor
Can you create code to select an engine first, before selecting the fuel tank?

AFAIK FS only uses one fuel tank at a time.


Resource contributor
Assuming you mean FS2020 and not FS2000 :) and assuming Asobo have not fixed the 'fuel tank problem'...

The fuel tanks do not operate the way you think they should. For individual tanks on the P-38, stick to Center, Center2, Center3, External1 and External2. If you try to use Main, FS burns through Main, Aux and Tip all at the same time. For the Ki-43 you need to fudge the issue. For each pair of tanks use e.g. Center(x) and External(x), then use a timer to switch between them (say) every ten seconds. That will give the effect of two tanks in use at the same time.

I'm also assuming that the FS2020 SDK is now in a usable state where the engines and fuel are concerned.


Resource contributor
Ha! Just realised from the other thread that you really are using FS2000. In which case, all comments above about the fuel tanks definately apply.
Hello Gentlemen,

Perhaps the comments above don't apply as much as you might think.

In Combat Flight Simulator, there actually are no "External Tanks", so I can't use those at all.
When entering the simulator, the default situation is for One LEFT tank to be selected, One Right tank to be selected and one Center tank to be selected all at once.
If Main, Aux, and Tip tanks exist on each side, the first tank to be used on each side will be the Aux tank.
After that, the Main tank is used. The Tip tank is always ignored.

On the Centerline, Center3 is used first, then Center2 and then Center1.

As soon as a particular tank is selected, you are then drawing from that tank or if your selector offers the option, you can go back to "All" tanks which was the default situation. I have been programming my Fuel Selectors to detect the "All Tanks" situation and to change it to a known selection instead.


The "Unmodified" P-38 has a pair of fuel tanks on each side in the wing roots.
The Main on each side is 93 Gallons and should be drawn from first.
The Reserve tank on each side is 60 Gallons and sits ahead of the Mains.

There are gauges on the panel to display the quantity of each tank, so combining them together causes other problems.
Life gets even worse with the "Modified" P-38 (Late J series and all L Models) which have an additional outboard wing tank on each side.
There is no gauge for those tanks.
Since I am not working on those (yet) I am not concerned yet about accessing the Tip tank on each side.


It seems that without the ability to select an engine and multiple tanks, the best solution is to use some fancy logic to keep track of the tanks in use for each engine and to draw from each using a timer to switch.
Now I just need to learn how to use a timer to do that,

The results may not be completely accurate. (If power settings and fuel consumption are not the same on both sides, but it may be the best that I can do.)


- Ivan.


Resource contributor
double tankTimer1 = 0;
int tankFlag1 = 0;

// Switch tanks every ten seconds
if(tankTimer1 == 180)
tankTimer1 = 0;
if(tankFlag1)tankFlag1 = 0; else tankFlag1 = 1;
//switch to tank 2
//switch to tank 1
Thank You, DragonflightDesign,

Your code example just gave me an "Aha moment".
I had always been under the impression that the delay parameter was a specification for a timer for an interrupt and it didn't occur to me that the gauge code was being executed exactly 18 times per second. I was thinking there was a timer parameter or clock I had to keep track of.

Next comes the issue of how to cut an engine when its fuel supply runs out.
It seems to me that the best approach would be to set mixture to idle-cutoff.
Turning off magnetos obviously won't work because the change in magneto status will be picked up by the magneto gauge.
The mixture control is not an ideal situation either because its status will also be picked up by the throttle controls.

We shall see where this leads. The concept of this gauge pair just became very different from what I was originally thinking.

- Ivan.


Resource contributor
Next comes the issue of how to cut an engine when its fuel supply runs out.
It seems to me that the best approach would be to set mixture to idle-cutoff.
The mixture control is not an ideal situation either because its status will also be picked up by the throttle controls.
That's how I do it on the current project. I separate the visuals from the mixture values. I can't give you a code sample this time but the flow looks something like this:

- read the mixture demand from keyboard, flight controls or mouse call
- calculate where the mixture levers should be dependant on the demand
- display the mixture levers in that position
- override the input demand and set the actual mixture to lean cut-off

There's no reason why you can't use a similar approach with the mag switches. In fact, I wish I had. It would have been so much simpler.
Hello DragonflightDesign,

I believe it is much more optimal to use mixture to cut engines rather than the magnetos for the following reasons:

The vast majority of the military aircraft (with the exception of trainers and the like) were flown with "Auto-mixture", typically Auto-Lean for economical cruise and Auto-Rich for Take Off and Combat. No one flew with manual mixture in maneuvering combat, The conditions changed too quickly and there wasn't enough of a power gain to justify it nor was there time to wait for conditions to stabilize to detect the power increase.
CFS works differently to encourage using manual mixture. Power increase over auto-mixture is around 17% from my own testing.
In reality on a 1150 HP engine, the gain was more on the order of 25-50 HP at best and usually a lot less which is barely noticeable.
This is under ideal test conditions and the pilot has a chance to back off if he detects detonation as a result of mixture tuning.
Thus most of my AIR files do not have Panel controllable mixture. It is either on or off and that is it, so losing that control is not significant.

On the other hand, the B-5 style twin engine magneto gauge I programmed will pretty much ignore the settings that keyboard controls are commanding and set whatever its own switches indicate. That is because it made no sense to reflect the changing settings when the master switch was off and it didn't seem appropriate to flip the individual magneto controls once the master switch was turned on.
I believe that having the mag switch try to set what it believes is correct and a fuel selector try to cut the engine with a magneto setting would create an unpredictable race condition.

- Ivan.


Resource contributor
I believe that having the mag switch try to set what it believes is correct and a fuel selector try to cut the engine with a magneto setting would create an unpredictable race condition.
They are two different sets of code. Mags on and lean cut is an acceptable setup - it's an RL setup.
Hello DragonflightDesign,

Here is why I believe that my B-5 Magneto Gauge and a Fuel Selector that both try to set the state of magnetos would cause a race condition:
The typical Magneto Gauge detects the current state of magnetos and sets itself to that state. If there are multiple magneto switches on a panel, changing the settings on one will cause the other to change state as well even though it is different code.

With the B-5, it doesn't read the current state of the magnetos. It tries to set them to what it believes they should be as determined by its own switch status. If something else changes the mag settings, it will reset them the next time it runs..... So what you would have is two gauges each doing their own thing and trying to set the mag status to what each thinks it should be. The Magneto gauge would keep trying to turn magnetos on while the Fuel Selector would keep trying to turn them off.
The same thing would happen with mixture controls but I don't think it would affect as much for aircraft that are not supposed to have panel control over mixture.

I am fairly certain this would happen because many of the recent fuel selectors I have programmed will detect a state that they do not consider valid and reset to something that is valid. Typically, "ALL" tanks are selected when entering the simulator or starting engines with the "E" key.
This means a tank is selected from each of the Left, Right and Center groups and that is not valid for many aircraft and also gives a garbage reading on many fuel gauges that show quantity for selected tanks. I try to detect that situation and reset to a single existing tank.

- Ivan.


Resource contributor
Trust me - the mags, mixtures, throttles, fuel tanks etc. are all on different code 'streams'. There is no cross feed there at all. I honestly think you're seeing problems that don't exist.
Hello DragonflightDesign,

Perhaps you are right. I am a fairly experienced C developer but just a beginner with Gauge programming.

I see Gauge Macros as just a bunch of function declarations as library (DLL) code but with no obvious control flow because I have no idea what the function calls actually look like. I have some hints just from seeing the gauges operate but that is about it.
I know SOMETHING is being called 18 times per second, but am not really sure which functions are being run and in what order.
(No, I have not taken the time to see what kind of code the pre-processor actually generates.)
The only obvious parts where I believe I can embed C code for the timer are in callback functions and in the library declaration.
I can't see any reason why the library declaration would need to run more than once, so it is unlikely to be the proper place.
A for callbacks, I currently have one gauge for each engine's fuel selector so that I can locate the two dials where I want on the panel.
They use the same callbacks but each gauge calls them separately. I believe a little experimentation can determine the proper coding for timing.
Hopefully I will get a little smarter in time.

- Ivan.
Last edited: