Author Topic: How to handle toggle switches in DCS?  (Read 1449 times)

NickT

  • Newbie
  • *
  • Posts: 2
How to handle toggle switches in DCS?
« on: January 06, 2020, 10:28:33 AM »
Gudday, long time reader, first time poster  :)
I've been tinkering with Voice Attack more and more recently, and I'm really hoping someone here can help me figure out how to work better with some toggle switches in a DCS cockpit. Here's what I've got; I created this 'Fox 2' Voice Attack macro command for the DCS A-4E-C:
  - Select Pylon 2 (this is toggle on/off)
  - Select Pylon 4 (also toggle on/off)
  - Master Arm ON (toggle)
  - Guns to SAFE (toggle)
  - Weapon selector dial to Bombs & GM Arm
  - Guns to READY (toggle)

This works really well, except that after it's run, the toggles are all left selected. So if I then run a different Voice Attack macro command that involves any of these toggles, they are then toggled OFF instead of ON.

I know there's a way to 'check' the status of these switches within a macro, using 'IF/THEN' conditionals or even Boolean or True/False, but I must admit after much YouTubing, forum browsing and RTFM, I'm still a little lost (not a strong coder :-\).

Can anyone help a fellow Voice Attacker out?
Thanks in advance!

Cheers, Nick  :D

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: How to handle toggle switches in DCS?
« Reply #1 on: January 06, 2020, 10:59:25 AM »
You could set a Boolean variable to keep track of toggle switch positions, however if you change a switch by clicking it ingame, the variable will no longer have the same state as the ingame switch.

It is theoretically possible to get ingame switch states for DCS using LUA scripting and a VoiceAttack plugin, but I'm not personally aware of anyone maintaining such a thing (it doesn't help that there is apparently no standardized method for getting these switch states in different modules).


This topic is an attempt to explain the basics of control flow ("IF/THEN").

A basic conditional keypress would look something like
Code: [Select]
Begin Boolean Compare : [>masterArm] Does Not Equal True
    Press Left Shift+M keys and hold for 0,06 seconds and release
    Set Boolean [>masterArm] to True
End Condition
I.E. if the last known toggle state is not on (represented by true), make it on and keep that value for later reference.

A command for switching the same control off would do the inverse: Check whether the toggle is off, and if not turn it off and save that value.

Make sure you check the "Evaluate 'Not Set' as false" option on the "Begin a Conditional (If Statement) Block" action's "True/False (Boolean)" tab.



A tip for switches that have multiple positions, have keyboard shortcuts for either direction, and stop at either end: Rather than keeping track of their state, unless whatever the switch is controlling would be adversely affected by doing so, you can go to either end position and work back or forward from there.

E.G. if you have a switch that has "off", "standby", and "on" positions, if you want "standby", you go toward off twice (in case the current state is "on"), then toward "on" once, making the final position "standby".
This can normally be done quickly enough to barely be noticeable.

If there are more positions, you can also optimize this by going to the side that's closest to the desired end position, E.G. if you have five positions, and you want the fourth, you'd go toward five five times, then one toward one to end up at four, rather than going toward one five times, then toward five four times.

NickT

  • Newbie
  • *
  • Posts: 2
Re: How to handle toggle switches in DCS?
« Reply #2 on: January 06, 2020, 12:05:57 PM »
Pfeil, I love your work mate  :D
I'll have a play with what you've recommended and let you know how I go, thanks a million for such a prompt response, and also for your commitment to helping all of the other posters in this forum.
Dead Set Legend ;)

Cheers!  ;D