Author Topic: Execute command based on a variable?  (Read 962 times)

PotatoJedi

  • Newbie
  • *
  • Posts: 15
Execute command based on a variable?
« on: October 09, 2020, 01:52:10 PM »
I have no idea how to word the subject to this. I think what I'm asking for is way outside of my ability to code anything. Here is what I need:

Imagine a hot bar with numbers 1-10. You can cycle through the hot bar with the left and right arrow keys and then execute the skill by pressing x (or whatever). What I want is to be able to say a number, have it cycle the appropriate number of times in the appropriate direction and then press x. If it's already on that number, it just presses x.

It would start at default position 1. If I say 5, it will move 4 times to the right (right arrow key 4 times) and then press x. It will then remember this position for future reference. If I say 8, it will check to see what position it's on (currently 5) and then move however many times and press x (in this case right 3 times). If I now say 4, it will go in the opposite direction (left 4 times, then press x). Finally, if I'm already on the number, it just presses x (so in this example saying 4 again just presses x).

Could someone help me code this? I have no clue what the appropriate terminologies are so I didn't know how to title this.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Execute command based on a variable?
« Reply #1 on: October 09, 2020, 02:04:36 PM »
This could work:
Hot bar [1..10]
Code: [Select]
Begin Integer Compare : [activeHotbarSlot] Has Not Been Set
    Set integer [activeHotbarSlot] value to 1
End Condition
Set integer [~targetHotbarSlot] value to the converted value of {TXTNUM:"{CMD}"}
Begin Integer Compare : [activeHotbarSlot] Is Less Than [~targetHotbarSlot]
    Start Loop While : [activeHotbarSlot] Is Less Than [~targetHotbarSlot]
        Press Right key and hold for 0,03 seconds and release
        Set integer [activeHotbarSlot] to [activeHotbarSlot] plus 1
    End Loop
Else
    Start Loop While : [activeHotbarSlot] Is Greater Than [~targetHotbarSlot]
        Press Left key and hold for 0,03 seconds and release
        Set integer [activeHotbarSlot] to [activeHotbarSlot] minus 1
    End Loop
End Condition
Press X key and hold for 0,03 seconds and release


These topics attempt to provide information on the basic concepts used:
https://forum.voiceattack.com/smf/index.php?topic=732.0
https://forum.voiceattack.com/smf/index.php?topic=3500.0

You can also press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on VoiceAttack's features.

PotatoJedi

  • Newbie
  • *
  • Posts: 15
Re: Execute command based on a variable?
« Reply #2 on: October 11, 2020, 06:25:05 AM »
Thank you very much! That works splendidly. And also thank you for giving me those links – I started reading through some of it. Getting a better grasp on how it works now.

Reading through the documentation it doesn't seem possible to make the dynamic commands have just the numbers in them, is it? So instead of saying hotbar [1..10] you can just say the number range and have it work. I tried doing it and VA wouldn't recognise it as a command. Not a big deal, at any rate. This works just fine.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Execute command based on a variable?
« Reply #3 on: October 11, 2020, 01:01:21 PM »
That is certainly possible; "[1..10]" will generate the numbers one to ten as command phrases.

If the command is not recognized, check the log to see what the speech recognition engine thinks it's hearing. Also make sure your speech recognition profile is well-trained; Run through the speech recognition training at least three times.

PotatoJedi

  • Newbie
  • *
  • Posts: 15
Re: Execute command based on a variable?
« Reply #4 on: October 11, 2020, 07:13:59 PM »
Got it to work, but for some reason it seems to be very picky. Here's a screenshot of what I mean. Sometimes it recognises it and sometimes not. Should I do more speech recognition training or..? It works just fine if I put a word before it.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Execute command based on a variable?
« Reply #5 on: October 11, 2020, 07:30:11 PM »
It looks like the speech recognition engine is recognizing what you're saying, but it's not getting linked to the command phrase.

Which speech recognition engine are you using?


While it's a workaround, what you could do is replace
Code: [Select]
Set integer [~targetHotbarSlot] value to the converted value of {TXTNUM:"{CMD}"}with
Code: [Select]
Set integer [~targetHotbarSlot] value to the converted value of {TXTWORDTONUM:"{CMD}"}and replace [1..10] with one;two;three;four;five;six;seven;eight;nine;ten


It is worth mentioning that speech recognition in general is more accurate the more data it has to work with; Single-word (especially single-syllable word) commands are less likely to get recognized consistently.

If you haven't trained you speech recognition profile three times already, you'll definitely want to do so, but otherwise the above workaround may be a usable option.

PotatoJedi

  • Newbie
  • *
  • Posts: 15
Re: Execute command based on a variable?
« Reply #6 on: October 12, 2020, 07:14:43 AM »
I'm using Microsoft Speech Recogniser 8.0 for Windows. Just the standard built in thing. I don't know if there is a way to get it to use Dragon's speech engine otherwise I would probably use that as I'm also using Dragon Professional Individual for my dictation.

I ran the training again as you suggested but it doesn't seem to have done anything. The workaround however seems to be working except "ten" doesn't seem to work. Here is what it says.



Not really sure what's up with that.

Edit: got rid of "ten" and just added in "zero" at the start, so now it's 0-9 instead of 1-10. That seems to work.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Execute command based on a variable?
« Reply #7 on: October 12, 2020, 07:19:41 AM »
Aha, right. The "{TXTWORDTONUM:}" token converts written numbers from zero to nine, so it won't work on "ten" (because it doesn't need to; The speech recognition should recognized two-digit numbers as digits).

Change the command phrase to one;two;three;four;five;six;seven;eight;nine;10

PotatoJedi

  • Newbie
  • *
  • Posts: 15
Re: Execute command based on a variable?
« Reply #8 on: October 14, 2020, 07:05:59 AM »
Works flawlessly now, thank you! Been using it all day yesterday without any issues. Much appreciated. Now all I need to do is try to figure out how the code actually works for my own curiosity xD.