Author Topic: Create a single command where each keyword has the option to turn it on and off  (Read 1984 times)

keysnbrz

  • Newbie
  • *
  • Posts: 1
Guys, how do I make a single command for three actions, where each one comes with its option to turn it on and off?

Example: When I say "on cargoscoop" or "off cargoscoop", a different action and audio for each spoken phrase, including the other phrases: "on hardpoints"; "off hardpoints"; "on landinggear"; off landinggear. Basically, I want an on and off button for three spoken options, all in a single command created. I leave a print of a command I made with this proposal, but I don't know how to put a switch on and off for each word I quoted above: hardpoints; landinggear; cargoscoop



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
There are a few things that could be done differently here...

You're using the "{CMD}" token to get the entire spoken phrase, but then using the "{TXTREPLACE:}" token to remove part of that phrase (though you're removing "open" rather than "on", which won't work as that's not part of the spoken phrases).

If you had used the "Contains" or "Ends With" operator in your conditions, that would not be necessary, and even if it were necessary, the "Set a Text Value" action has a built-in "Replace" option that would be more efficient than using a token for a single replace, or you could nest the "{TXTREPLACEVAR:}" token to replace both at once, E.G.
Code: [Select]
{TXTREPLACEVAR:"{TXTREPLACEVAR:"{CMD}":"on ":""}":"off ":""}
Also note the spaces in "on " and "off "; If you don't remove the space and use the "Equals" operator, " cargoscoop" does not match "cargoscoop". Whitespace counts.

"{TXTREPLACEVAR:}" is used in these examples, as "{TXTREPLACE:}" is deprecated (it does not appear in the official documentation for this reason).


To check for one keyword, and then the other, you can nest conditions inside each other, E.G.
Code: [Select]
Begin Text Compare : [{CMD}] Ends With 'cargoscoop'
    Begin Text Compare : [{CMD}] Starts With 'on'
        Say, 'cargo scoop deployed'
    Else
        Say, 'cargo scoop retracted'
    End Condition
    Press 1 key and hold for 0,06 seconds and release
Else If Text Compare : [{CMD}] Ends With 'hardpoints'
    Begin Text Compare : [{CMD}] Starts With 'on'
        Say, 'hardpoints on'
    Else
        Say, 'hardpoints on'
    End Condition
    Press 2 key and hold for 0,06 seconds and release
Else
    Begin Text Compare : [{CMD}] Starts With 'on'
        Say, 'landing gear deployed'
    Else
        Say, 'landing gear retracted'
    End Condition
    Press 3 key and hold for 0,06 seconds and release
End Condition

In most cases using a suitable operator like "Contains", "Starts With", or "Ends With" is enough to differentiate between the different possibilities.

You can also consider which options are mutually exclusive, or have been ruled out already, and use a regular "Else", rather than an explicit "Else If", E.G. because if the phrase starts with "on", it logically cannot also start with "off".
That is something of a personal preference in this case, so you should go with the option that is most readable to you.


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

These topics may also be of use:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up