Author Topic: sorry but i really need help for find a logic for a code  (Read 2393 times)

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
sorry but i really need help for find a logic for a code
« on: December 22, 2017, 10:28:06 AM »
Hello Team,
In my cockpit, i have a rothery Fasten-Seatbelts with 3 positions:
Off - Auto - On

I have a dataref equals those positions: 0 - 1 - 2

i have code in spadnext Send to VA SeatBeltsOn when data is 1 or 2.

In VA on command SeatBeltsOn, playaudio a file.wav

The problem:, it's a rothery, so, if the pilot turn it from 0 to 2, it pass on 1 and i have 2 time the audio file.

Someone have an idea.

I hope i'm almost clear with my bad english.

Thanks to all and happy christmas.

Best regards,
Guillaume.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: sorry but i really need help for find a logic for a code
« Reply #1 on: December 22, 2017, 09:40:32 PM »
If you can get the actual state of the "Fasten Seatbelts" sign, you could trigger off that instead, but I doubt many addons actually simulate it.


If you're executing a single command twice, you can either:

Have the first execution set a variable to log the last time the command was executed, so that the second execution can be ignored if it occurs within a certain amount of time from the first.

Or, have the first execution wait for a set amount of time, and if there is a second execution, the first is ignored, and the second runs instead.

The delay for either would depend on how quickly you anticipate rotating the knob. If you can do so with a relatively quick flick of the wrist, a 1000ms delay could strike a good balance between false positives and false negatives(Where the command doesn't run twice while it should, or runs twice while it shouldn't).


The main issue with such an approach is that without knowing which way the knob is rotated, the sound would still play potentially when it shouldn't(when returning the knob from "On" to "Off", or "On" to "Auto").

If you can, you'd pass the current position to VoiceAttack, which combined with the delay would determine the behavior.

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: sorry but i really need help for find a logic for a code
« Reply #2 on: December 22, 2017, 10:29:06 PM »
Hello Pfeil,

OK thanks, i have solved my problem like that:

On SeatBeltsOn, i kill SBOff and SBAuto, wait 5s (if a wav is on play) and play the wav for SBOn

And the "same" for others.

Thank you. Have a good day.