Author Topic: Loop with increasing pause  (Read 1211 times)

MaximoKnight

  • Newbie
  • *
  • Posts: 3
Loop with increasing pause
« on: October 21, 2020, 10:14:31 PM »
Hi guys,

I'm fairly new to VA, and I am not a developer, however I find VA useful for many things, and I am enjoying always finding more way to automate things in my day to day life using VA.
I am not a programmer but I can pick things up fairly fast, having said all that, I am challenged with making something I have never made before.
and increasing pause within a loop, I have no idea if VA can do such a thing but I will attempt to explain

I would like it to press and hold a key repeatedly, and each time it presses it, to increase the length of time it holds it for

all I can think of explaining is a very very basic basic language, but something like this:

x=0
loop 50
x= x+1
Press down T
pause x
release T
End loop

basically loop 1 will hold T for 1 second, loop 2 will hold it for 2 seconds etc. for 50 loops
hopefully I explained myself well and there is a way to do this.

Thank You

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Loop with increasing pause
« Reply #1 on: October 21, 2020, 10:43:14 PM »
Hi, there

This can be done - the command would look like this:

Start Loop : Repeat From 1 to 50
    Press down T key
    Pause a variable number of seconds [{INT:intIndex}]
    Release T key
End Loop

This involves adding a 'for' loop (loop a certain number of times).  This is where you set the range of 1 to 50.  You also declare the indexer of intIndex in there as well.  Inside the loop, T goes down, then a variable pause.  Note the variable pause is rendering the integer indexer (intIndex) as a token and converting it rather than using a decimal variable.  After the pause, T is released.

I've attached a profile with that command so you can look at it.  Hope that helps!

MaximoKnight

  • Newbie
  • *
  • Posts: 3
Re: Loop with increasing pause
« Reply #2 on: October 21, 2020, 11:09:03 PM »
That does help, I think, :)

I think I follow you, however if I wanted to change the pause value lets say one time is 1 sec per loop instance

but in a different loop I wanted to add 0.500 seconds each loop instance, or a 0.0750 seconds what would I do differently?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Loop with increasing pause
« Reply #3 on: October 21, 2020, 11:28:05 PM »
Code: [Select]
Start Loop : Repeat From 1 to 50
    Press down T key
    Convert integer [intIndex] to decimal [decIncrement]
    Set decimal [decIncrement] to [decIncrement] times 0.5
    Pause a variable number of seconds [decIncrement]
    Release T key
End Loop

Now that we're needing a decimal value, we're using a decimal variable.  We're converting the integer variable (intIndex) into a decimal variable (decIncrement), then multiplying that decimal variable by 0.5.  The variable pause can accept a decimal variable, so we just use 'decIncrement' there.

Another way to do this would be to use the {EXPDECINV:expression} token:

Code: [Select]
Start Loop : Repeat From 1 to 50
    Press down T key
    Pause a variable number of seconds [{EXPDECINV:{INT:intIndex} * 0.5}]
    Release T key
End Loop

That's an expression token that can do the calculation.  Since the token is resolving to a decimal value, the variable pause can accept it.

MaximoKnight

  • Newbie
  • *
  • Posts: 3
Re: Loop with increasing pause
« Reply #4 on: October 21, 2020, 11:57:19 PM »
aaahhhh
both make perfect sense now that you draw it out for me.
I think the second one is cleaner and any time I can reduce lines I'm all for it :)
I tested it and it seems to work Exactly as I wanted it to, thank you soo much!