Author Topic: Voice Attack read joysticks analog sticks?  (Read 3856 times)

Learwolf

  • Guest
Voice Attack read joysticks analog sticks?
« on: September 25, 2017, 12:35:41 PM »
Voice Attack doesnt seem to recognize my joysticks analog sticks or L2/R2 triggers. Is this normal or am I missing something?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Voice Attack read joysticks analog sticks?
« Reply #1 on: September 25, 2017, 01:06:31 PM »
VoiceAttack can recognize button presses to trigger commands, not analog input.

If you're using a controller with progressive triggers(XBox360/One PS3/PS4), those are analog inputs as well(In the Xbox 360 drivers I tried way back, the triggers were actually combined into a single axis, not sure if that's still the case).


You could set up a command containing a loop to monitor analog axes for movement/position by using the joystick state tokens(E.G. "{STATE_JOYSTICK1X}" or "{STATE_JOYSTICK1Y}", and have that trigger other commands.

E.G.
Code: [Select]
Start Loop While : [{EXP:1=1}] Equals '1'
    Begin Condition : ([{EXP: {STATE_JOYSTICK1X} > 50000}] Equals '1' AND [~Trigger1] Equals False)
        Execute command, 'target command' (and wait until it completes)
        Set Boolean [~Trigger1] to True
    Else If Text Compare : [{EXP: {STATE_JOYSTICK1X} < 45000}] Equals '1'
        Set Boolean [~Trigger1] to False
    End Condition
End Loop
This example will trigger the target command as soon as the left stick is moved far enough to the right. The stick then has to be moved back towards the center to rearm the system before the target command can be executed again.

I put in a margin of 5000 units to prevent a jittery pot from accidentally triggering the target command twice as the stick is moved back towards the center.

Learwolf

  • Guest
Re: Voice Attack read joysticks analog sticks?
« Reply #2 on: September 25, 2017, 01:37:43 PM »
Ahh, that explains it. Thanks Pfeil!
Gonna go look over the tokens list again now.

::Edit::
Hey Pfeil, would having the stick move left (opposite direction of your example) be 0 and 5000 replacements? And I'm assuming {STATE_JOYSTICK1/2Z} references the top triggers?
« Last Edit: October 04, 2017, 11:09:55 AM by Learwolf »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Voice Attack read joysticks analog sticks?
« Reply #3 on: October 05, 2017, 04:24:36 AM »
50000 isn't the maximum range of the stick(The internal value is a 16bit integer, which tops out at 65535), so symmetrical values would be 15535 and 20535.
As a side note, while the internal value is 16bit, most controllers aren't anywhere near that precise; The XBox 360 controller only provides 8bit resolution(only 255 different values) IIRC.
This means that the value will jump significantly, as those 255 values are "mapped" onto a range from 0 to 65535.

I do believe the Z axis would be the triggers on an XBox-style controller, though you can verify this by opening "Devices and Printers", right-clicking your controller, selecting "Game Controller Settings" from the context menu, and double-clicking your controller in the list(These steps work in Windows 7, but may be slightly different in other versions of Windows).
Now you can move the different analog controls and see which axes they correspond to.

If you want to see a live readout of an axis, you can have VoiceAttack run a loop that outputs one or more joystick token values to the log:
Code: [Select]
Start Loop While : [{EXP:1=1}] Equals '1'
Write '[Blue] X:{STATE_JOYSTICK1X} Y:X:{STATE_JOYSTICK1Y}' to log
Pause 0,05 seconds
End Loop
I added a pause because while VoiceAttack can process the values quite fast, the log cannot be updated nearly as quickly, so running it unrestrained can result in VoiceAttack becoming less/unresponsive.

Learwolf

  • Guest
Re: Voice Attack read joysticks analog sticks?
« Reply #4 on: October 05, 2017, 07:26:27 AM »
Thank you for the help Pfeil, I greatly appreciate it!