Author Topic: Loop  (Read 2960 times)

Phadebas

  • Newbie
  • *
  • Posts: 7
Loop
« on: August 22, 2020, 06:56:50 AM »
Hi there - love VoiceAttack, the things I have been able to make it do in combination with Elite Dangerous and other third party tools never ceases to amaze me!

In my tinkering with the commands, I have come across a situation with the "Loop" command that  I don't think I am able to address with the command as it currently is (apologies if I am wrong!).

Sometimes, I set my commands with a Single condition (while loop) - whilst I am waiting for a variable/token in voice attack to be changed by a third party tool (EDDI / Elite Dangerous) - example attached.  However, I don't necessarily want it to loop forever (in case the 3rd party instruction is never received, or I only want it to wait a certain time before the command moves on (i.e. loop while [A] = true, or loop X number of times (whichever happens first))

Is it feasible that the "Add a (while) loop" command could offer as an option to also loop a maximum number of times?

Apologies if there is a simple way to already do this - but, if so, I can't find it.

Many thanks for your hard work and for taking the time to read my suggestion!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Loop
« Reply #1 on: August 22, 2020, 12:15:39 PM »
If you want a loop to only run a given amount of times, you can either use a while loop with a manual iterator, or a for loop with an additional condition, both of which use actions that are already available.

E.G.
Code: [Select]
Set integer [~i] value to 0
Start Loop While : ([Status fsd status] Equals 'masslock' AND [~i] Is Less Than 3)
    Press Tab key and hold for 0.03 seconds and release
    Pause 0.25 seconds
    Set integer [~i] to [~i] plus 1
End Loop

or

Code: [Select]
Start Loop : Repeat 3 Times
    Begin Text Compare : [Status fsd status] Equals 'masslock'
        Press Tab key and hold for 0,01 seconds and release
        Pause 0,25 seconds
    End Condition
End Loop


That said, the example you provide doesn't just wait, as it presses the key every ~250ms as long as the condition is true, and if the condition isn't true to begin with, it won't loop at all.

If what you want is to wait for a condition to evaluate to true for a given amount of time, you can use a date value and a while loop, E.G.
Code: [Select]
Set date [~timeout] to [~timeout] plus [2] seconds
Start Loop While : [~timeout] Is After Current Date/Time
    Begin Text Compare : [Status fsd status] Equals 'masslock'
        Press Tab key and hold for 0,01 seconds and release
        Loop Break
    End Condition
    Pause 0,25 seconds
End Loop
which will wait for the condition to become true, at which point it would press the tab key, or for the time to run out, at which point execution of the command will jump to the "Loop End" action.

Phadebas

  • Newbie
  • *
  • Posts: 7
Re: Loop
« Reply #2 on: August 22, 2020, 10:07:32 PM »
Hi Pfeil - thank you so much, these are all really nice solutions to the situation :).

Come to think of it, I have used loop with an internal 1 s pause before as a rudimentary "timer" within commands so I suppose it is just an extension of that.

Thanks again!