P3D v4 Apparent repeat when single event wanted

Roy Holmes

Resource contributor
#1
I appear to be having more than one event occur after I use the following code. I'm using FSX schema and multiple macros.

Code:
<Trigger id="LANDING_LIGHT_HOME">
        <KeyEvent>LANDING_LIGHT_HOME</KeyEvent>
        <Script>
                   Do something once
    </Script>
I have the relevant button on my stick set to no repeat but I usually get two events happening.
Could be my stick is getting old and trembling a bit (like me) but I'd like to come up with a way to cancel the "Do something once" code after it happens once.
I suppose what might be happening is that because the above code is not in line with the program cycling it may be affecting two cycles.
The do something is a series of actions.
Anyone got an idea on how to fix this?
Roy
 
#2
I'll take a swing at it.

Events and traps are queued and processed sequentially at the end of each cycle. What if you use the value in a storage register to conditionally process the 'do something once' code. The idea is similar to an init sequence often used in gauges. My presumption is that the double/multiple event is thrown in the same cycle as the initial one:

Code:
<Trigger id="LANDING_LIGHT_HOME">
  <KeyEvent>LANDING_LIGHT_HOME</KeyEvent>
    <Script>
       l20 0 ==
         if{
           Do something once
           1 s20
         }
    </Script>

At the start of the next cycle, register 20 will be back to 0. I don't know when registers are cleared ... before queued events are processed? after? That would make a difference.

I haven't tested this and I have some doubts that it will work, but it would at least be simple to try. I'll also note that I'm unfamiliar with <Trigger>, so apologies if I've missed something related to that.

The other idea is to remap the event trap to use another button on the joystick to see if you get better action.

Bob
 

taguilo

Resource contributor
#3
At the start of the next cycle, register 20 will be back to 0. I don't know when registers are cleared ... before queued events are processed? after? That would make a difference.
Hi Bob,
Register values in <Event> scripts are cleared after the script is executed. It means your solution won't (or shouldn't) work, considering Roy declares the event is executed twice.
A solution I use in different situations is this:

Code:
    <Script>
       (L:MyVar,bool) 
        if{
             0 (>L:MyVar,bool) 
           }
        els{
                Do something once
                 1 (>L:MyVar,bool) 
             }
   </Script>
This will work for a unintended duplicated event. Bear in mind it won't if the event is executed only once.

Tom
 
#4
Roy,
Most likely you have already checked, just adding 2 cents.. Have you checked to see if the button itself is sending 2 commands? Possibly on the down press and then on the release?
A quick check with FSUIPC logging "non-axis events" will confirm.

Roman
 

Roy Holmes

Resource contributor
#5
Roman,
That was a good idea. I have not checked with FSUIPC but if I press down and delay the release two events happen from the down press and none from the release. I'm firing guided weapons. One guides and the other goes ballistic and dances around. I'll try the suggested code changes.
Roy
 
#6
Roy,

The code change could run into trouble if your trembling old joystick ever fires three or more events, or somehow happens to fire the duplicate events but in sequential gauge update cycles (is that what you're getting at in your initial post?).

If so, you could try something like this:

Code:
<Update>
    (L:MyVar, bool) 1 ==
        if{
            (L:CycleCount, enum) ++ (>L:CycleCount, enum)
            (L:CycleCount, enum) 2 ==
                if{ 0 d (>L:MyVar, bool) (>L:CycleCount, enum) }
        }           
</Update>                   

<Script>                   
    (L:MyVar, bool) !
        if{
            Do something once
            1 (>L:MyVar, bool)
        }
</Script>

Or this

Bob
 

Roy Holmes

Resource contributor
#7
I put a "drop counter" in the event script which showed that I was getting two drops for every press. I used the "myvar" code from Tom and it allowed only one drop. I then reset the lvar in an update which happened sufficiently long after the first drop so that I could make more than 1.
So what I ended up with was:
Code:
 <Script> (L:MyVar,bool)  0 ==
        if{ (L:dropcount, number) 1 + (&gt; L:dropcount, number) 1 (>L:MyVar,bool) @weapon_drop }
       </Script>
And a call to
Code:
<Macro Name="myvar">
        <MacroValue>
        0 (>L:MyVar,bool)
                      </MacroValue>
    </Macro>
In a update.
That allowed me to make 6 single drops one after the other with each weapon guiding to target

I came back to post this and found my friend Bob had done much the same thing!
I used the 0 state of myvar so that it accepted the first input and barred the second. That took care of the situation where someone else might not have the issue.
Roy
 
Top