Author Topic: Assistance Required - Using part of the spoken command as a variable  (Read 1777 times)

dryh2o

  • Newbie
  • *
  • Posts: 16

So what I want to do is speak a command like, "move forward 7 times" and be able to pull the "7" (or whichever number is spoken) into my actual command to determine the number of times to loop.

I have the spoken command formatted exactly like this (minus the quotes, of course): "move forward (1..25) times"

And what I have so far in the command:

Code: [Select]
Convert text [{CMDSEGMENT:2}] to small integer [TimesToRepeat]
Start Loop While : [TimesToRepeat] Is Greater Than Or Equals 1
    Press W key and hold for 0.01 seconds and release
    Pause 0.01 seconds
    Set integer [TimesToRepeat] to [TimesToRepeat] minus 1
End Loop

I Googled around and tried a few different things, but what I have above is pretty close - if even possible. Still playing with it, but I thought I'd stop and ask for help before I spent all night on it.

I tried using TimesToRepeat in the box for a for loop in place of the number of times to repeat, but it didn't seem to like that or I am formatting my variables wrong. Any help here is very much appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #1 on: July 12, 2020, 03:37:06 PM »
You're mixing datatypes; "TimesToRepeat" is a small integer, yet you're decrementing an integer by the same name (which is a functionally a different variable entirely).

There is no real benefit to using small integer over integer, so I'd recommend using regular integers (small integer may be deprecated at some point, too)


That said, rather than doing this manually, use the "Loop Start - Repeat a Certain Number of Times" action (I.E. a For loop), where you can put the token directly into the "Number of times" field and VoiceAttack will do the rest for you.

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #2 on: July 12, 2020, 04:02:05 PM »
When I have attempted to use a variable or token into the text box of the For Loop (Repeat a certain number of times) command, I always get an error:

"Unable to resolve for loop context: RepeatMe" (if I put only the variable RepeatMe name in the box

or

"Unable to resolve for loop context: {CMDSEGMENT:2}" (if I place the token in the box)

That's why I tried the while loop, thinking that I was not going to be able to use a variable or token in that field for the for loop.

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #3 on: July 12, 2020, 04:03:56 PM »

Meant to add this...

Code: [Select]
Convert text [{CMDSEGMENT:2}] to integer [RepeatMe]
Start Loop : Repeat [RepeatMe] Times
    Press W key and hold for 0.01 seconds and release
    Pause 0.01 seconds
End Loop

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #4 on: July 12, 2020, 04:07:40 PM »
If your command name is literally
Code: [Select]
move forward (1..25) timesthat is not the correct syntax for a numeric range, which is why the token cannot be resolved (as it does not return a number).

Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, and check the "Dynamic command sections" subsection of the "Command Screen" section for the correct syntax.


If you're working with tokens, and something it's working as expected, use the "Write a Value to the Event Log" action to verify the output of the token(s), E.G.
Code: [Select]
Write [Blue] '{CMDSEGMENT:2}' to log

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #5 on: July 12, 2020, 04:19:43 PM »
In my haste, I typed it wrong. My current testing command is: "move backward [1..25]"

I was (and am) using square brackets.

Also, I am looking at the PDF. It says exactly what you've said, "Then, you can find out how many items to build by checking {CMDSEGMENT:1}.  The rendered value will be, ‘5’ (which you can convert and use in a loop, for inst"

Evidently, I am missing something obvious. I've created enough VA commands that I thought I'd have no issues figuring this out, yet I keep getting stuck.

https://imgur.com/lDILUKC

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: Assistance Required - Using part of the spoken command as a variable
« Reply #6 on: July 12, 2020, 04:23:14 PM »
I've gotten it. {CMDSEGMENT:2} should have been {CMDSEGMENT:1}.

Thank you for your help.