Detecting joysticks/gamepads
by Jason Reid · in Torque Game Builder · 09/18/2006 (4:01 pm) · 2 replies
Is there any way for me to detect the availability of joystick0, joystick1, etc, via TorqueScript? On my main menu, for example, I would like to "gray out" a 2-player option if there is no joystick connected to the PC. Also, when allowing player 1, player 2, etc to pick their control scheme, I only want to let them each pick a joystick if there are 2 connected.
#2
09/18/2006 (8:13 pm)
Ah, sweet...thanks! Right now I only have one joystick to test with, but your code worked for autodetecting that one, and I don't see why it wouldn't work for the others. When I get my second, I'll post a follow-up just to confirm my (hopeful) success, unless someone else beats me to it.
Torque Owner Teck Lee Tan
isJoystickDetected()
will return true if any are detected, and false otherwise.
enableJoystick() is supposed to return true or false, depending on success, but I haven't been able to get a return value so far.
Hmm, a bit more experimentation has me thinking this might work, though I don't actually have a gamepad/joystick at work to test with. :p
getJoystickAxes(n)
is meant to return the stick position of the X and Y axes of joystick n, but a quick test without a joystick connected returns nothing. So:
$joystickCount = 0; for(%n = 0; %n < 4; %n++) { if (!getJoystickAxes(%n)) { echo("Joystick" SPC %n SPC "not detected"); } else { echo("Joystick" SPC %n SPC "detected"); $joystickCount++; } } echo($joystickCount SPC "joysticks detected");That should loop through and let you know which, and how many, joysticks are attached. Not tested, so use at your own risk. :p
edit: Oops, I guess there's no break() in TS. :p