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

P3D v2 How does this gauge work?

Messages
10,163
Country
us-arizona
Hey guys,

Can someone please explain to me the basics of how this gauge operates? I have been staring at it for 2 hours and thought its time to ask a professional how it actually works.

Here is the ModelDef code (its a fuel selector, custom done) and below this will be my questions about it;


Code:
<PartInfo>
        <Name>switch_fuel_selector_da40</Name>
        <AnimLength>150</AnimLength>
        <Animation>
            <Parameter>
                <Code>
                (L:SET_FLAG, number) 0 ==
                if{ 1 (&gt;L:SET_FLAG, number)
                (A:FUEL TANK SELECTOR:1, enum) 0 ==
                if{ 0 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 2 ==
                if{ 30 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 16 ==
                if{ 150 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 3 ==
                if{ 90 (&gt;L:SELECT_POS,number) }
                }
                els{
                (L:SELECT_POS, Number)
                }
        </Code>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <HelpID>HELPID_GAUGE_FUEL_SELECTOR</HelpID>
            <TooltipID>TOOLTIPTEXT_FUEL_SELECTOR</TooltipID>
    <MouseFlags>LeftSingle+LeftRelease+LeftDrag+Wheel</MouseFlags>
    <CallbackCode>
      (M:Event) 'LeftSingle' scmp 0 ==
      if{
        (M:Y) (&gt;L:MOUSEPOS,number)
        quit
      }
    
      (M:Event) 'LeftDrag' scmp 0 ==
      if{
        (M:Y) (L:MOUSEPOS,number) - 0.2 * (L:SELECT_POS,number) + 0 max 75 min (&gt;L:SELECT_POS,number)
        (M:Y) (&gt;L:MOUSEPOS,number)
      }
    
      (M:Event) 'LeftRelease' scmp 0 ==
      if{
        (L:SELECT_POS,number) 20 &lt;
        if{
        0 (&gt;L:SELECT_POS,number)
        16 (&gt;K:FUEL_SELECTOR_SET)
        }
        21 45 (L:SELECT_POS,number) rng
        if{
        25 (&gt;L:SELECT_POS,number)
        2 (&gt;K:FUEL_SELECTOR_SET)
        }
        46 55 (L:SELECT_POS,number) rng
        if{
        50 (&gt;L:SELECT_POS,number)
        3 (&gt;K:FUEL_SELECTOR_SET)
        }
        70 75 (L:SELECT_POS,number) rng
        if{
        75 (&gt;L:SELECT_POS,number)
        0 (&gt;K:FUEL_SELECTOR_SET)
        }
      }
        </CallbackCode>
        </MouseRect>
    </PartInfo>


Question one: In the first part, in the <Code> section, why does this need to occur? Is this starting the part to zero point (animation position) when the plane boots up?

<Code>
(L:SET_FLAG, number) 0 ==
if{ 1 (&gt;L:SET_FLAG, number)

////////////////////////////////////////////////////////////////////////////////////////////////////

Question two: In the top part, in the <Code> section, the animations are given. I have no idea how this is working. I take it that 1, 0, 30, 150, and 90 are the movements which coincides with scale of 150 KF's. Is it saying that if fuel tank selector is at '16', then move to KF position 150?

Code:
                <Code>
                (L:SET_FLAG, number) 0 ==
                if{ 1 (&gt;L:SET_FLAG, number)
                (A:FUEL TANK SELECTOR:1, enum) 0 ==
                if{ 0 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 2 ==
                if{ 30 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 16 ==
                if{ 150 (&gt;L:SELECT_POS,number) }
                (A:FUEL TANK SELECTOR:1, enum) 3 ==
                if{ 90 (&gt;L:SELECT_POS,number) }
               }
                els{
               (L:SELECT_POS, Number)
                }
        </Code>

////////////////////////////////////////////////////////////////////////////////////////////////////

Question three: (More like verification), I take it that (M:Y) means Y axis mouse movement.

////////////////////////////////////////////////////////////////////////////////////////////////////

Question four: What is being stated here? One is mouse clicking and its stating no number amount and then terminates. What is its cause?

(M:Event) 'LeftSingle' scmp 0 ==
if{
(M:Y) (&gt;L:MOUSEPOS,number)
quit
}

////////////////////////////////////////////////////////////////////////////////////////////////////

Question five: The last portion of the Mouse section shows ranges and numbers. Those must be the key frames? Or are they (M:Y) movements? I note that these only occur with LeftRelease actions. They also have fuel selector commands, but how does the switch know what point to move to?

(M:Event) 'LeftRelease' scmp 0 ==
if{
(L:SELECT_POS,number) 20 &lt;
if{
0 (&gt;L:SELECT_POS,number)
16 (&gt;K:FUEL_SELECTOR_SET)
}
21 45 (L:SELECT_POS,number) rng
if{
25 (&gt;L:SELECT_POS,number)
2 (&gt;K:FUEL_SELECTOR_SET)
}
46 55 (L:SELECT_POS,number) rng
if{
50 (&gt;L:SELECT_POS,number)
3 (&gt;K:FUEL_SELECTOR_SET)
}
70 75 (L:SELECT_POS,number) rng
if{
75 (&gt;L:SELECT_POS,number)
0 (&gt;K:FUEL_SELECTOR_SET)
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////

Question six: Back to <Code> (animation), is this stating that if the fuel enum is at 16, then move to KF 150? (I think I can answer this one, as I have been writing these questions, I think I am figuring out a few of the things that make this function, answer being yes, if fuel selector 16 is active, then move this part to KF 150).

(A:FUEL TANK SELECTOR:1, enum) 16 ==
if{ 150 (&gt;L:SELECT_POS,number) }


Sorry for all the questions. This one has always mesmerized me and I have more uses for something like this but have no idea how it basically all works. For instance, how does it know to move the certain amounts of mouse travel scaled with the actual switch? For instance, if this was a huge lever, how would I make the mouse travel 'more' to compensate the giant lever being worked? ( <-- Question seven, sigh..... )

Example, is this stating how many pixels the mouse travels? 0 thru 75? And what is -0.2 * for?

(M:Y) (L:MOUSEPOS,number) - 0.2 * (L:SELECT_POS,number) + 0 max 75 min (&gt;L:SELECT_POS,number)
(M:Y) (&gt;L:MOUSEPOS,number)
 
Last edited:
Bill,

This example is in some aspect similar to the example I gave you in the turbine thread. The fuel lever is positioned by draggin on the Y (vertical) scale.

(L:SELECT_POS, Number) var holds the current position of the lever, using its animation scale, for a total of 150 Kf.
Possible values of (L:SELECT_POS, Number) are 0, 30, 90 and 150.
These kf values are linked to (A:FUEL TANK SELECTOR:1, enum) with this relationship:

SelectPos 0 FuelTankSel 0
SelectPos 30 FuelTankSel 2
SelectPos 90 FuelTankSel 3
SelectPos 150 FuelTankSel 16

When the model loads, (L:SELECT_POS, Number) will be 0 but (A:FUEL TANK SELECTOR:1, enum) might be in other position than 0, so what (L:SET_FLAG, number) does it to handle the init process as to make a correct link between SelectPos and FuelTankSel. This is made only once for the entire aircraft's session, as SetFlag is toggled to 1 so the init code won't execute again. I guess this shoud answer questions one and two.

You are correct in question three.

Answering question four, when LeftSingle the current Y value (position) is saved onto (L:MOUSEPOS,number) as an init value to be compared against new ones on every drag movement. Then, when releasing the mouse button by LeftRelease, depending on which range of the Y scale the release action took place the corresponding kf value is assigned to SelectPos and the event affecting FuelTankSel is also triggered. I hope this answers your question five.

Your own answer to question six is correct.

Regarding your last questions, 0.2 is a scale reduction factor and we don't know the amount of pixels the mouse travels but we know that the area supported by SelectPos is set to a height of 75 pixels, because of 0 max 75 min (>L:SELECT_POS,number)

Hope this helps

Tom
 
Many thanks Tom. What an exotic bit of code. I use this on the Diamond DA40 and Robin DR400 and always wanted to know how it worked.
 
Back
Top