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

FS2004 Can't capture button press

Messages
36
Country
argentina
I'm trying to make a gauge that, when the trim button is pressed, a variable is changed but the trim is not moved. So, this is what I did:

Code:
<Element>
        <Keys>
            <On Event="ELEV_TRIM_DN">
                (A:Sim On Ground,bool) ! if{ (>K:ELEV_TRIM_UP)
                (L:FBW_ref, number) 0.5 + (>L:FBW_ref, number) }
            </On>
        </Keys>
</Element>

<Element>
        <Keys>
            <On Event="ELEV_TRIM_UP">
                (A:Sim On Ground,bool) ! if{ (>K:ELEV_TRIM_DN)
                (L:FBW_ref, number) 0.5 - (>L:FBW_ref, number) }
            </On>
        </Keys>
</Element>

Since I found that the gauge did not react as expected, I tried changing the event for PROP_PITCH_INCR/_DECR:

Code:
<Element>
        <Keys>
            <On Event="PROP_PITCH_INCR">
                (A:Sim On Ground,bool) ! if{ (L:FBW_ref, number) 0.5 + (>L:FBW_ref, number) }
            </On>
        </Keys>
</Element>

<Element>
        <Keys>
            <On Event="PROP_PITCH_DECR">
                (A:Sim On Ground,bool) ! if{ (L:FBW_ref, number) 0.5 - (>L:FBW_ref, number) }
            </On>
        </Keys>
</Element>

I removed the opposite trim movement line, since it was no longer required. But still does not react. Did I do something wrong?
 
Remove the Element tag and use the ELEVATOR_TRIM_SET to prevent jamming with TRIM_UP/DN endless loop.
Code:
<Gauge>
...
<Keys>
    <On Event="ELEV_TRIM_DN">
        (A:Sim On Ground,bool) ! if{ 0 (>K:ELEVATOR_TRIM_SET)
        (L:FBW_ref, number) 0.5 + (>L:FBW_ref, number) }
    </On>
    <On Event="ELEV_TRIM_UP">
        (A:Sim On Ground,bool) ! if{ 0 (>K:ELEVATOR_TRIM_SET)
        (L:FBW_ref, number) 0.5 - (>L:FBW_ref, number) }
    </On>
</Keys>
...
</Gauge>
 
As Luka says, the <Keys> section works much like the <Mouse> section so you should only use one <Keys> section.

Check also to see if it still works when you are in the exterior view. I have found in the past that <Keys> don't work unless you are in the virtual cockpit view although I may be mistaken. I only tried it once a few years ago and when it didn't work for me I changed to using a C++ gauge to handle events.
 
Thanks, Luka and Anthony. Since it won't do anything visual, I already have this gauge installed into [Vcockpit01] (same place where Posky/TDS/SkySpirit leaves their XML gauge animations). I guess there should be no problem.

Regarding the possible infinite loop, thanks for pointing out this possibility. Now I have another 2 more questions:

1) I want to leave the trim untouched while in flight. Thus, Luka's code would be changed into this:

Code:
<Gauge>
...
<Keys>
    <On Event="ELEV_TRIM_DN">
        (A:Sim On Ground,bool) ! if{
        (L:FBW_ref, number) 0.5 + (>L:FBW_ref, number) }
    </On>
    <On Event="ELEV_TRIM_UP">
        (A:Sim On Ground,bool) ! if{
        (L:FBW_ref, number) 0.5 - (>L:FBW_ref, number) }
    </On>
</Keys>
...
</Gauge>

With this code, if I press the trim button inflight, would I be moving the trim?

2) Is it there any equivalence between (>K:ELEV_TRIM_DN) and this?

Code:
(A:ELEVATOR TRIM INDICATOR, number) X - (>K:ELEVATOR_TRIM_SET)

I mean, what would be the value of X? This taking into account that both ELEVATOR_TRIM_INDICATOR and ELEVATOR_TRIM_SET go between -16k and +16k.
 
1) I want to leave the trim untouched while in flight.

What you actually need is "cancel" the UP and DOWN events by triggering the opposite one in each case.
And you must use a flag variable to avoid entering an endless loop :

Code:
<Keys>
<On Event="ELEV_TRIM_DN">
    (L:TrimDownByCode,bool) !
    if{        
         (A:Sim On Ground,bool) !
         if{  (>K:ELEV_TRIM_UP)
              (L:FBW_ref, number) 0.5 + (>L:FBW_ref, number)
              1 (>L:TrimUpByCode,bool)
            }
         }
    0 (>L:TrimDownByCode,bool)
</On>

<On Event="ELEV_TRIM_UP">
    (L:TrimUpByCode,bool) !
    if{
         (A:Sim On Ground,bool) !
         if{  (>K:ELEV_TRIM_DN)
              (L:FBW_ref, number) 0.5 - (>L:FBW_ref, number) }
              1 (>L:TrimDownByCode,bool)
            }
       }
     0 (>L:TrimUpByCode,bool)
</On>
</Keys>

Making

Code:
(A:ELEVATOR TRIM INDICATOR, number) X - (>K:ELEVATOR_TRIM_SET)

is always possible but won't be as exact -in this case - as triggering the opposite event.

Tom
 
¡Muchas gracias, Tom! I'm currently using PROP_PITCH as the trigger event, it works beautifully. After I finish coding everything, I'll try to change trigger event to ELEVATOR_TRIM.
 
Back
Top