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

MSFS20 Fuel Selector logic

Messages
94
I have found that the logic and code to control a fuel selector control is much more difficult that I expected. The screenshot below shows the type of fuel valve I was trying to model. It can rotate around four positions for Both, right, off, then left. You would like it to grab with the mouse and drag around to each position and it fires the event to set that tank as the active. But I tried so many different methods to achieve this.

fuel_selector.png


So the problem is that the index numbers for the tanks are not in a sequential order, so you need to remap any incremental value of the switch position to the appropriate tank indexes. Here's how I solved it so far.

I added two planes to accept the mouse clicks. The material is invisible with collision.

fuel_selector_click.png


This is the code for each side.

XML:
        <Component ID="Fuel_Select_CW" Node="Fuel_Select_CW">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <!-- eval the current tank ID and show which tank will be selected next -->
                 <TOOLTIPID>Set Fuel to
                     %(( A:FUEL TANK SELECTOR:1, Enum) 0 ==)%{if}RIGHT%{else}
                     %(( A:FUEL TANK SELECTOR:1, Enum) 1 ==)%{if}RIGHT%{else}
                     %(( A:FUEL TANK SELECTOR:1, Enum) 2 ==)%{if}BOTH%{else}OFF%{end}
                 </TOOLTIPID>
                 <CURSOR>RightArrow</CURSOR>
                 <!-- 4 cases = if 0(off):3(right), 1(all):3(right), 2(left):1(on), 3(right):0(off) -->
                <LEFT_SINGLE_CODE>0 1 3 3 4 (A:FUEL TANK SELECTOR:1, Enum) case (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>d
            </UseTemplate>   
        </Component>
        <Component ID="Fuel_Select_CCW" Node="Fuel_Select_CCW">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <!-- eval the current tank ID and show which tank will be selected next -->
                 <TOOLTIPID>Set Fuel to
                     %(( A:FUEL TANK SELECTOR:1, Enum) 0 ==)%{if}LEFT%{else}
                     %(( A:FUEL TANK SELECTOR:1, Enum) 1 ==)%{if}LEFT%{else}
                     %(( A:FUEL TANK SELECTOR:1, Enum) 2 ==)%{if}OFF%{else}BOTH%{end}
                 </TOOLTIPID>
                 <CURSOR>LeftArrow</CURSOR>
                 <!-- 4 cases = if 0(off):3(left), 1(all):2(left), 2(left):0(off), 3(right):1(on) -->
                <LEFT_SINGLE_CODE>1 0 2 2 4 (A:FUEL TANK SELECTOR:1, Enum) case (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>
            </UseTemplate>   
        </Component>

The tooltip shows what the next selection will be if you click. But the tricky part is the code section. I'm using a case statement which is very oddly specified in RPN style. 0 1 3 3 4 (A:FUEL TANK SELECTOR:1, Enum) case (&gt;K:FUEL_SELECTOR_SET)

The last number before the simvar (4) indicates how many cases there are. The cases are 0 1 3 3. When (A:FUEL TANK SELECTOR:1, Enum) is 0, the case operator returns 0. When it's 1, it returns 1. If 2, return 3 and if 3, return 3.

The animation of the lever is pretty easy and has the same trick.

Code:
        <Component ID="FUEL_Switch_Selector" Node="FUEL_Switch_Selector">
            <UseTemplate Name="ASOBO_GT_Anim">
                <ANIM_NAME>FUEL_Switch_Selector</ANIM_NAME>
                <!-- frame 0=1(all) frame 100=2(left) frame 200=0(off) frame 300=3(right) -->
                <ANIM_CODE>3 1 0 2 4 (A:FUEL TANK SELECTOR:1, Enum) case 100 *</ANIM_CODE>
                <ANIM_LENGTH>400</ANIM_LENGTH>
                <ANIM_WRAP>TRUE</ANIM_WRAP>
                <ANIM_LAG>300</ANIM_LAG>
            </UseTemplate>           
        </Component>

When (A:FUEL TANK SELECTOR:1, Enum) is 0, return 3, 1 = 1, 2 = 0 and 3 = 2. Then multiply by 100 to match the 400 frame animation in Blender.

I'm curious to see if anyone else has solved this type of problem and if it's possible to have a similar logic with a freely draggable control.
 
Really useful example

I adapted it to my aircraft where I have two independent selectors to enable left or right or all tanks (if both are switched)
 
I am glad this was useful for someone. At the time, I thought it would be a good example about how to use the case statement in RPN.
Since then, I settled on a better implementation of the All, Left, Right, Both fuel selector. I now use four click spots, each covering a quadrant of the fuel selector. This way, the user can see the intended action with the tool tip and be certain that one click will select the intended tank and not end up shutting off the fuel inadvertently.


XML:
<Component ID="FUEL_SYSTEM">

        <!-- click quadrants to select fuel tanks -->
        <Component ID="FUEL_SELECTOR_CLICK_ALL" Node="FUEL_SELECTOR_CLICK_ALL">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <TOOLTIPID>Set Fuel to BOTH</TOOLTIPID>
                 <CURSOR>Grab</CURSOR>
                <LEFT_SINGLE_CODE>1 (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>
            </UseTemplate>   
        </Component>
        <Component ID="FUEL_SELECTOR_CLICK_LEFT" Node="FUEL_SELECTOR_CLICK_LEFT">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <TOOLTIPID>Set Fuel to LEFT</TOOLTIPID>
                 <CURSOR>Grab</CURSOR>
                <LEFT_SINGLE_CODE>2 (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>
            </UseTemplate>   
        </Component>
        <Component ID="FUEL_SELECTOR_CLICK_OFF" Node="FUEL_SELECTOR_CLICK_OFF">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <TOOLTIPID>Set Fuel to OFF</TOOLTIPID>
                 <CURSOR>Grab</CURSOR>
                <LEFT_SINGLE_CODE>0 (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>
            </UseTemplate>   
        </Component>
        <Component ID="FUEL_SELECTOR_CLICK_RIGHT" Node="FUEL_SELECTOR_CLICK_RIGHT">
             <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
                 <TOOLTIPID>Set Fuel to RIGHT</TOOLTIPID>
                 <CURSOR>Grab</CURSOR>
                <LEFT_SINGLE_CODE>3 (&gt;K:FUEL_SELECTOR_SET)</LEFT_SINGLE_CODE>
                <EVENTID/>
            </UseTemplate>   
        </Component>
        
    


        <Component ID="FUEL_Switch_Selector" Node="FUEL_Switch_Selector">
            <UseTemplate Name="ASOBO_GT_Anim">
                <ANIM_NAME>FUEL_Switch_Selector</ANIM_NAME>
                <!-- frame 0=1(all) frame 100=2(left) frame 200=0(off) frame 300=3(right) -->
                <ANIM_CODE>3 1 0 2 4 (A:FUEL TANK SELECTOR:1, Enum) case 100 *</ANIM_CODE>
                <ANIM_LENGTH>400</ANIM_LENGTH>
                <ANIM_WRAP>TRUE</ANIM_WRAP>
                <ANIM_LAG>300</ANIM_LAG>
            </UseTemplate>           
        </Component>   

     </Component>
 
Back
Top