Author Topic: using variables to turn a toggle command into multiple inputs  (Read 2249 times)

sawi98

  • Newbie
  • *
  • Posts: 8
so I started playing dcs world and started setting up a profile for it, but being new I'm having a hard time doing more complex stuff, here's the exact issue.

my plane uses shift+l to control position lights and it toggles them from off->on->blinking.
so, instead of having to repeat the command multiple times I tried setting it up so that I can specify how I want them and voiceattack will know how many time to press the button or if the lights are already set how I want them to.
here's how I went about it.

I set the command to recognize the phrase " position lights [on;off;set to blink]

then set the first variable "pos lights cmd" to {CMD}

then used {TXTREPLACE:pos lights cmd:position lights:} so it would only say either on, off or set to blink.

I added a write to log event saying "pos light cmd recognized as: {TXT:pos light cmd}

so far so good, everything was going fine so I start working on the second part

if 'pos light cmd' equals on and 'pos lights status' equals not set, off or set to blink

say "turning on position lights ( I would have put the part about recognizing how many presses of the button were needed here) and set "pos lights status" to on

if pos light cmd equals on and pos lights status also equals on say "position lights are already on" and do nothing

this way it wouldn't get messed up if I said turn lights on twice and I could've added a second command like check position lights to read position lights status but here's the problem:
after this every time I tried testing the command it would recognize it as set to blink regardless of what I say

anyone knows what's up with that or if there's a better way to go about it?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: using variables to turn a toggle command into multiple inputs
« Reply #1 on: May 12, 2020, 11:22:17 AM »
Right-click the action list and choose "Copy All as Text", then paste that into a code block (click the "#" above the post textbox to add the tags) here, so the actual contents of your command are presented in a readable format.

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #2 on: May 12, 2020, 01:54:11 PM »
Code: [Select]
Set text [pos lights cmd] to '{CMD}'
Set text [pos lights cmd] to '{TXTREPLACE:pos lights cmd:position lights: }'
Write [Blue] 'detected as {TXT:pos lights cmd}' to log
Begin Condition : ([pos lights cmd] Equals ' on' AND [pos lights status] Equals 'off; set to blink; ')
    Say, 'turning position lights on'
    Set text [pos lights status] to 'on'
    Write [Blue] 'pos lights: on' to log
Else If Text Compare : [pos lights status] Equals 'on'
    Say, 'positon lights already on'
    Write [Blue] 'no action taken' to log
End Condition


hope this is what you mean. btw now that I re-started voiceattack the
Code: [Select]
Write [Blue] 'detected as {TXT:pos lights cmd}' to log part works again like normal but the if condition still doesn't activate

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #3 on: May 12, 2020, 01:55:25 PM »
and I almost forgot, thank you

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: using variables to turn a toggle command into multiple inputs
« Reply #4 on: May 12, 2020, 02:12:52 PM »
Code: [Select]
Set text [pos lights cmd] to '{TXTREPLACE:pos lights cmd:position lights: }'"{TXTREPLACE:}" is a token that only exists for backwards compatibility; Use the documented "{TXTREPLACEVAR:}" token instead.

Code: [Select]
Begin Condition : ([pos lights cmd] Equals ' on' AND [pos lights status] Equals 'off; set to blink; ')You need to check each value individually, a semicolon-delimited list will not work; Either way, checking whether the status does not equal on, rather than checking whether it equals one of all the other possible values, would be more appropriate.

Also note that a text variable that hasn't been set will return the literal text "Not set", not a blank value.

Code: [Select]
Else If Text Compare : [pos lights status] Equals 'on'Is redundant if you do check every possible other value beforehand, as logically by excluding everything else there is only one remaining value that would cause execution to reach this block.


Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer for the documentation on these features.


Instead of using "{TXTREPLACEVAR:}", you could use the "Ends With" operator of the "Begin a Conditional (If Statement) Block" action to check the value of the "{CMD}" token directly, as you're setting your status variable manually anyway.

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #5 on: May 12, 2020, 05:09:54 PM »
I tried rewriting and completing the command following your advice (aside the ends with part that I did not understand).
now the set to blink issue is back, the log says that neither of the three if blocks activated and the tts earrapes when I activate it.

here's the full command
Code: [Select]
Set text [nav lights cmd] to '{CMD}'
Set text [nav lights cmd] to '{TXTREPLACEVAR:nav lights cmd:navigation lights: }'
Write [Blue] 'detected as {TXT:nav lights cmd}' to log
Begin Condition : ([nav lights cmd] Equals ' on' AND [nav lights status] Does Not Equal 'on')
    Begin Condition : [nav lights status] Equals 'off' OR [nav lights status] Equals 'not set'
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    Else
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    End Condition
    Say, 'turning navigation lights on'
    Set text [nav lights status] to 'on'
    Write [Blue] 'nav lights: on' to log
Else
    Say, 'navigation lights already on'
    Write [Blue] 'no action taken' to log
End Condition
Begin Condition : ([nav lights cmd] Equals 'off' AND [nav lights status] Does Not Equal 'off')
    Begin Text Compare : [nav lights status] Equals 'set to blink'
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    Else
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    End Condition
    Say, 'turning navigation lights off'
    Set text [nav lights status] to 'off'
    Write [Blue] 'nav lights: off' to log
Else
    Say, 'navigaton lights already off'
    Write [Blue] 'no action taken' to log
End Condition
Begin Condition : ([nav lights cmd] Equals 'set to blink' AND [nav lights status] Does Not Equal 'set to blink')
    Begin Text Compare : [nav lights status] Equals 'on'
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    Else
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
        Press Right Ctrl+L keys and hold for 0.1 seconds and release
    End Condition
    Say, 'setting navigation lights to blink'
    Set text [nav lights status] to 'set to blink'
    Write [Blue] 'nav lights: set to blink' to log
Else
    Say, 'navigation lights already set to blink'
    Write [Blue] 'no action taken' to log
End Condition

where did I go wrong now? thanks again for your time, I know it must be frustating trying to help absolute beginners

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: using variables to turn a toggle command into multiple inputs
« Reply #6 on: May 12, 2020, 05:17:33 PM »
Code: [Select]
Set text [nav lights cmd] to '{TXTREPLACEVAR:nav lights cmd:navigation lights: }'Do you have a variable named "navigation lights" and a variable named " "? If not, this will not work as currently configured; Read the documentation on the token.

In addition, why are you attempting to replace text with a space character when you can replace it with nothing, effectively keeping only the part you're interested in?

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #7 on: May 13, 2020, 02:43:46 AM »
I might have misunderstood how the command works but my intention was to subtract the words navigation lights from the variable "nav lights cmd" and I thought I had to replace it with a space character to do that. am I supposed to do it like
Code: [Select]
Set text [nav lights cmd] to '{TXTREPLACEVAR:nav lights cmd:navigation lights:}' ?

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #8 on: May 13, 2020, 02:46:18 AM »
tried that, result is the same but now "nav lights cmd" it's stuck on not set instead of set to blink

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: using variables to turn a toggle command into multiple inputs
« Reply #9 on: May 13, 2020, 09:27:30 AM »
Did you read the documentation? The reason the token is returning "Not set" is because you're passing in literal text values as if they're variable names.

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #10 on: May 13, 2020, 02:10:02 PM »
I did read the documentation.
I didn't get it

I chose to switch back to {TXTREPLACE} and that fixed the part where nav lights cmd wasn't being trimmed correctly
 now the remaining problem is that all the if statements are being activated simultaneously and they all register as already on/off/set to target, which makes me suspect the real issue is with the nav lights status variable that is supposed to be responsible for the part that determines the outcome of the if's states

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: using variables to turn a toggle command into multiple inputs
« Reply #11 on: May 13, 2020, 02:33:57 PM »
Why are you using a token to replace text at all?

As you're not reusing the value of "{CMD}" directly, you can, as mentioned, use the "Ends With" operator (I.E. click the dropdown in your "Begin a Conditional (If Statement) Block" action that says "Equals" now, and change it to "Ends With") to check which option was spoken.

If you do insist on replacing text, there is a section at the bottom of the configuration window for the "Set a Text Value" action labeled "Text Options", where you can use the "Replace" option to replace text directly.


If you don't have the "Evaluate 'Not Set' as empty (blank)" option checked, any statement comparing that value to literal text will return false, which is the correct behavior for null ("Not set", in VoiceAttack) values as defined in the C# language specification.

sawi98

  • Newbie
  • *
  • Posts: 8
Re: using variables to turn a toggle command into multiple inputs
« Reply #12 on: May 14, 2020, 03:40:57 PM »
got it now, I am an idiot. it's working fine now so thank you and sorry if I got annoying