Author Topic: Cycling between 2 commands  (Read 5348 times)

Scouto

  • Guest
Cycling between 2 commands
« on: August 24, 2016, 06:41:24 AM »
Need a little help setting up a command, can't figure it out using the documentation (I'm likely missing something very simple lol)

I have a command to put 4 pips to SYS and 2 pips to ENG when I say "Power to systems and engines", and another command to put 4 pips to SYS and 2 pips to WEP when i say "Power to systems and engines".

What I'm trying to do now is create a command, so that when I say "Cycle power", it will alternate between those 2 commands.

So far all I can manage is to have them both run 1 after the other.

Any help would be appreciated!

Technomancer

  • Jr. Member
  • **
  • Posts: 98
  • I have a bad feeling about this...
Re: Cycling between 2 commands
« Reply #1 on: August 24, 2016, 10:03:23 AM »
I did something similar, but went another route eventually.  Here's how I set it up initially.  I'm sure Commander Data...err...Pfiel will have a better method. ;)

You'll have to "initialize" the [TogglePower] variable (or whatever you want to call it, just make sure your change the Jump to Marker instruction to match the change also) before you can toggle it.  If you have a command running at VA start up, set the BOOLEAN there: i.e.

Set a BOOLEAN value
Variable Name: TogglePower
Set to True or False, I don't think it really matters, it'll just toggle from there.

Here's a screen:


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Cycling between 2 commands
« Reply #2 on: August 24, 2016, 02:32:56 PM »
Set a BOOLEAN value
Variable Name: TogglePower
Set to True or False, I don't think it really matters, it'll just toggle from there.
That's the way to do it, if you're looking for a simple toggle:

Cycle power
Code: [Select]
Begin Boolean Compare : [CyclePower] Does Not Equal True
    Execute command, 'Power to systems and weapons'
    Set Boolean [CyclePower] to True
Else
    Execute command, 'Power to systems and engines'
    Set Boolean [CyclePower] to False
End Condition

It's important to note that due to a "quirk" in VoiceAttack, an unset Boolean produces weird results, which in this case means the second command will execute first when VoiceAttack starts.

Also, I've opted to literally execute the commands, rather than duplicating their actions. This means a change to either command will not require updating the cycle command.


If you're looking to use the single commands as well as the cycle command, you can set the Boolean from the individual command so that the cycle command will produce the desired result:

Power to systems and engines
Code: [Select]
Set Boolean [CyclePower] to False
Power to systems and weapons
Code: [Select]
Set Boolean [CyclePower] to True
In this case you don't need to set the Boolean in the cycle command, as that's just redundant.

Scouto

  • Guest
Re: Cycling between 2 commands
« Reply #3 on: August 25, 2016, 05:42:53 AM »
Awesome guys! Thanks a lot! I don't think I would ever have figured this out :D

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Cycling between 2 commands
« Reply #4 on: August 26, 2016, 01:53:18 AM »
Here's another example for you. You could even have it switch between more then 2 options if you want.

Begin Small Integer Compare : [Pic Dev Switch] Has Not Been Set
    Set small int (condition) [Pic Dev Switch] value to 1
End Condition
Begin Small Integer Compare : [Pic Dev Switch] Equals 1
    Set small int (condition) [Pic Dev Switch] value to 2
    Run application 'C:\Running AHK scripts\Save Pics.ahk'
End Condition - Exit when condition met
Begin Small Integer Compare : [Pic Dev Switch] Equals 2
    Set small int (condition) [Pic Dev Switch] value to 1
    Run application 'C:\Running AHK scripts\Dev Tools.ahk'
End Condition - Exit when condition met

I actually use this as a selector though, but should work for what you want. Here's another command, which is the other half of the first. Meaning, you have to hit a different key to activate it.

Begin Small Integer Compare : [Pic Dev Switch] Has Not Been Set
    Set small int (condition) [Pic Dev Switch] value to 1
End Condition
Begin Small Integer Compare : [Pic Dev Switch] Equals 1
    Press Left Ctrl+Left Shift+C keys and hold for 0.1 seconds and release
End Condition - Exit when condition met
Begin Small Integer Compare : [Pic Dev Switch] Equals 2
    Press down Right Ctrl+Right Alt keys
    Click left mouse button
    Release Right Ctrl+Right Alt keys
End Condition

You use the first command as a selector, that makes the second command always run the same command when you hit the button. Hit the selector, and now it will always runs the second half.

This way, you can make a button, have more then one command, that you manually control the rotation between commands.

The first one would just be a toggle switch though. but you could toggle a 3rd, and 4th, and so on with it.