Author Topic: I think a problem whith my Compare  (Read 4046 times)

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
I think a problem whith my Compare
« on: April 04, 2017, 01:56:22 AM »
Hello Pfeil,

i need your help one more time.
So, i have a plane, Rotate MD80, i can't write directly the values like Airspeed, i must turn the knob.
So, i have do this code (the base is your original code), the problem is at the end, i can see the 2 Compares never start.

Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Set decimal [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] value to the value of [ActualAirSpeed]
Set Text [AirSpeed] to ''
Set Boolean [DictationComplete] to False
Say, 'yes ?'
Start Loop While : [DictationComplete] Equals False
    Start Dictation Mode (Clearing Dictation Buffer)
    Start Loop While : [{DICTATION}] Equals ''
    End Loop
    Stop Dictation Mode
    Begin Text Compare : [{EXP:{TXTNUM:"{DICTATION}"} >= 0}] Equals '1'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"{TXTNUM:"{DICTATION}"}"}'
    Else If Text Compare : [{DICTATION}] Equals 'zéro'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"0"}'
    Else If Text Compare : [{DICTATION}] Equals 'un'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"1"}'
    Else If Text Compare : [{DICTATION}] Equals 'deux'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"2"}'
    Else If Text Compare : [{DICTATION}] Equals 'trois'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"3"}'
    Else If Text Compare : [{DICTATION}] Equals 'quatre'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"4"}'
    Else If Text Compare : [{DICTATION}] Equals 'cinq'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"5"}'
    Else If Text Compare : [{DICTATION}] Equals 'six'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"6"}'
    Else If Text Compare : [{DICTATION}] Equals 'sept'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"7"}'
    Else If Text Compare : [{DICTATION}] Equals 'huit'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"8"}'
    Else If Text Compare : [{DICTATION}] Equals 'neuf'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"9"}'
    Else
        Play sound, 'C:\Windows\Media\Windows Ding.wav'
    End Condition
    Begin Text Compare : [{TXTLEN:AirSpeed}] Equals '3'
        Set Boolean [DictationComplete] to True
    Else If Text Compare : [{EXP:{TXTLEN:AirSpeed} > 3}] Equals '1'
        Say, 'can you repeat please ?'
        Set Text [AirSpeed] to ''
    End Condition
End Loop
Set decimal [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] value to the converted value of {TXT:Airspeed}
Write ' WantedAirspeed {DEC:XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED}' to log
Write ' actual {DEC:xplane!Rotate/md80/autopilot/at_target_speed}' to log
Begin Decimal Compare : [xplane!Rotate/md80/autopilot/at_target_speed] Is Less Than [xplane!SIM/COCKPIT/AUTOPILOT/AIRSPEED]
    Start Loop While : [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] Equals [xplane!Rotate/md80/autopilot/at_target_speed]
        Pause 0.1 seconds
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] plus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Write ' +1' to log
    End Loop
End Condition
Begin Decimal Compare : [xplane!Rotate/md80/autopilot/at_target_speed] Is Greater Than [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED]
    Start Loop While : [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] Equals [xplane!Rotate/md80/autopilot/at_target_speed]
        Pause 0.1 seconds
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] minus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Write ' -1' to log
    End Loop
End Condition
Say, 'airspeed is set {DEC:XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED}'
Write '[Purple] Airspeed {DEC:XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED}' to log



So, i think i forget just a little thing but i don't find.
Do you see where is my error ?
For information, before the first compare:
XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED is the wanted speed
xplane!Rotate/md80/autopilot/at_target_speed is the actual speed in the plane's autopilot.

Thank you very much.
Have a good day.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: I think a problem whith my Compare
« Reply #1 on: April 04, 2017, 02:24:06 AM »
Unless "AIRSPEED" and "at_target_speed" are already the same during the initial check, in which case running them would be pointless anyway, the bottom two loops will never start.

Both occurrences of
Code: [Select]
Start Loop While : [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] Equals [xplane!Rotate/md80/autopilot/at_target_speed]Should be
Code: [Select]
Start Loop While : [XPLANE!SIM/COCKPIT/AUTOPILOT/AIRSPEED] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: I think a problem whith my Compare
« Reply #2 on: April 05, 2017, 10:12:30 AM »
Hello Pfeil,
thanks, that was the problem but i have find some others now.
So, i continue to search.
Bye. Have a good day.

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: I think a problem whith my Compare
« Reply #3 on: April 06, 2017, 05:15:00 AM »
Hello Pfeil,

here my code now:

Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Set decimal [ActualAirSpeed] value to the value of [xplane!Rotate/md80/autopilot/at_target_speed]
Write ' Actual {DEC:ActualAirSpeed}' to log
Set Text [AirSpeed] to ''
Set Boolean [DictationComplete] to False
Say, 'yes ?'
Start Loop While : [DictationComplete] Equals False
    Start Dictation Mode (Clearing Dictation Buffer)
    Start Loop While : [{DICTATION}] Equals ''
    End Loop
    Stop Dictation Mode
    Begin Text Compare : [{EXP:{TXTNUM:"{DICTATION}"} >= 0}] Equals '1'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"{TXTNUM:"{DICTATION}"}"}'
    Else If Text Compare : [{DICTATION}] Equals 'zéro'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"0"}'
    Else If Text Compare : [{DICTATION}] Equals 'un'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"1"}'
    Else If Text Compare : [{DICTATION}] Equals 'deux'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"2"}'
    Else If Text Compare : [{DICTATION}] Equals 'trois'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"3"}'
    Else If Text Compare : [{DICTATION}] Equals 'quatre'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"4"}'
    Else If Text Compare : [{DICTATION}] Equals 'cinq'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"5"}'
    Else If Text Compare : [{DICTATION}] Equals 'six'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"6"}'
    Else If Text Compare : [{DICTATION}] Equals 'sept'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"7"}'
    Else If Text Compare : [{DICTATION}] Equals 'huit'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"8"}'
    Else If Text Compare : [{DICTATION}] Equals 'neuf'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"9"}'
    Else
        Play sound, 'C:\Windows\Media\Windows Ding.wav'
    End Condition
    Begin Text Compare : [{TXTLEN:AirSpeed}] Equals '3'
        Set Boolean [DictationComplete] to True
    Else If Text Compare : [{EXP:{TXTLEN:AirSpeed} > 3}] Equals '1'
        Say, 'can you repeat please ?'
        Set Text [AirSpeed] to ''
    End Condition
End Loop
Set decimal [SpeedTarget] value to the converted value of {TXT:Airspeed}
Begin Decimal Compare : [SpeedTarget] Is Greater Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] plus -1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] plus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
    End Loop
End Condition
Begin Decimal Compare : [SpeedTarget] Is Less Than [ActualAirSpeed]
    Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] minus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
    End Loop
End Condition
Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Write '[Purple] Airspeed {DEC:xplane!Rotate/md80/autopilot/at_target_speed}' to log
Say, 'airspeed is set {DEC:xplane!Rotate/md80/autopilot/at_target_speed}'



I stay with a problem i don't understand. I work only on the part where Actualspeed < SpeedTarget for the moment.
When i dictate my seed, the knob turn ok, the speed in the autopilot is ok but copilot (at the end of the code) say a speed = targetspeed -1

If i say 240, knob turn to 240 but copilot say: airspeed is set 239.
i don't see where is my error.

Could you have a look to my code ?

Thank you very much,

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: I think a problem whith my Compare
« Reply #4 on: April 06, 2017, 08:46:05 AM »
Hello,
finally, the problem is not the code. The problem is the time needed by computer to calculate and time for plugins to communicate between VA<>SpadNext<>XPlane.
So, i have do that and that's seem to work:

Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Set decimal [ActualAirSpeed] value to the value of [xplane!Rotate/md80/autopilot/at_target_speed]
Write ' Actual {DEC:ActualAirSpeed}' to log
Set Text [AirSpeed] to ''
Set Boolean [DictationComplete] to False
Say, 'yes ?'
Start Loop While : [DictationComplete] Equals False
    Start Dictation Mode (Clearing Dictation Buffer)
    Start Loop While : [{DICTATION}] Equals ''
    End Loop
    Stop Dictation Mode
    Begin Text Compare : [{EXP:{TXTNUM:"{DICTATION}"} >= 0}] Equals '1'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"{TXTNUM:"{DICTATION}"}"}'
    Else If Text Compare : [{DICTATION}] Equals 'zéro'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"0"}'
    Else If Text Compare : [{DICTATION}] Equals 'un'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"1"}'
    Else If Text Compare : [{DICTATION}] Equals 'deux'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"2"}'
    Else If Text Compare : [{DICTATION}] Equals 'trois'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"3"}'
    Else If Text Compare : [{DICTATION}] Equals 'quatre'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"4"}'
    Else If Text Compare : [{DICTATION}] Equals 'cinq'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"5"}'
    Else If Text Compare : [{DICTATION}] Equals 'six'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"6"}'
    Else If Text Compare : [{DICTATION}] Equals 'sept'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"7"}'
    Else If Text Compare : [{DICTATION}] Equals 'huit'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"8"}'
    Else If Text Compare : [{DICTATION}] Equals 'neuf'
        Set Text [AirSpeed] to '{TXTCONCAT:AirSpeed:"9"}'
    Else
        Play sound, 'C:\Windows\Media\Windows Ding.wav'
    End Condition
    Begin Text Compare : [{TXTLEN:AirSpeed}] Equals '3'
        Set Boolean [DictationComplete] to True
    Else If Text Compare : [{EXP:{TXTLEN:AirSpeed} > 3}] Equals '1'
        Say, 'can you repeat please ?'
        Set Text [AirSpeed] to ''
    End Condition
End Loop
Set decimal [SpeedTarget] value to the converted value of {TXT:Airspeed}
Begin Decimal Compare : [SpeedTarget] Is Greater Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] minus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] plus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
    End Loop
End Condition
Begin Decimal Compare : [SpeedTarget] Is Less Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] plus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] minus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
    End Loop
End Condition
Clear saved data from profile : decimal
Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Write '[Purple] Airspeed {DEC:xplane!Rotate/md80/autopilot/at_target_speed}' to log
Say, 'airspeed is set {DEC:xplane!Rotate/md80/autopilot/at_target_speed}'


If you see something to be improved....

Many thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: I think a problem whith my Compare
« Reply #5 on: April 06, 2017, 12:01:00 PM »
As the target airspeed can't be both higher and lower than the actual airspeed, the two states are mutually exclusive and can be part of the same conditional:
Code: [Select]
Begin Decimal Compare : [SpeedTarget] Is Greater Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] minus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] plus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
    End Loop
Else If Decimal Compare : [SpeedTarget] Is Less Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] plus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] minus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
    End Loop
End Condition

Aside from that, I don't know why you have
Code: [Select]
Clear saved data from profile : decimalin there. It won't clear out decimal variables, just the saved values in your profile(if there are any). Not sure what you're trying to do there.

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: I think a problem whith my Compare
« Reply #6 on: April 06, 2017, 12:51:48 PM »
Thanks for advice.
The clear it was because i thought the last part with text to speech not take the good value in the variable. So i removed it after my last post.

Pfeil,
how do you do for paste the code here like this ?
« Last Edit: April 06, 2017, 01:01:06 PM by Sloboda »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: I think a problem whith my Compare
« Reply #7 on: April 06, 2017, 01:33:21 PM »
Click the "#" button above the "Post reply" textbox, it'll add "code" tags either around your selection, or at your text cursor if you don't have anything selected. Put your code between the [code ] and [/code ] tags.

Sloboda

  • Jr. Member
  • **
  • Posts: 74
  • VoiceCommander Creator
    • A.M.I.S. X Plane
Re: I think a problem whith my Compare
« Reply #8 on: April 08, 2017, 02:50:59 AM »
Hello Pfeil,
thank you for advice. So, i'll try here.

I have win time in my code. I have remove a pause in the loop. In fac, the second pause 0.1s was needed just befor the getvalue before the text to speech. The knob turn more quickly now and the computer have time between the loop and the last getvalue, so the value of the variable in the TTS is OK:

Code: [Select]
Set decimal [SpeedTarget] value to the converted value of {TXT:Airspeed}
Begin Decimal Compare : [SpeedTarget] Is Greater Than [ActualAirSpeed]
    Set decimal [SpeedTarget] to [SpeedTarget] minus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] plus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
    End Loop
Else If Decimal Compare : [SpeedTarget] Is Less Than [ActualAirspeed]
    Set decimal [SpeedTarget] to [SpeedTarget] plus 1
    Start Loop While : [SpeedTarget] Does Not Equal [xplane!Rotate/md80/autopilot/at_target_speed]
        Set decimal [xplane!Rotate/md80/autopilot/speed_sel_knob] to [xplane!Rotate/md80/autopilot/speed_sel_knob] minus 1.00000
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
        Pause 0.1 seconds
        Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
    End Loop
End Condition
Pause 0.1 seconds
Execute external plugin, 'SPAD.neXt VoiceAttack Plugin - v0.9.5+' and wait for return
Write '[Purple] Airspeed {DEC:xplane!Rotate/md80/autopilot/at_target_speed}' to log
Say, 'airspeed is set {DEC:xplane!Rotate/md80/autopilot/at_target_speed}'