Page 1 of 1

Joystick Help Please

Posted: Mon Mar 02, 2015 9:05 pm
by i_love_u
I do not know whether the 2nd code snippet on this page is outdated or not, but it isn't working for me:
https://love2d.org/wiki/Joystick

I am also trying to use the function:

Code: Select all

love.gamepadpressed( joystick, button )
But it isn't working either. Does anyone have suggestions of what I am missing?

Re: Joystick Help Please

Posted: Mon Mar 02, 2015 9:20 pm
by Kingdaro
It's possible that your joystick isn't actually registered as a gamepad. Try putting this in your code (with console enabled in conf.lua):

Code: Select all

function love.joystickpressed(joystick, button)
   print(joystick, button)
end
Press buttons on your joystick, and if you get output, then that means you'll have to add gamepad mappings manually for your controller. See: love.joystick.setGamepadMapping.

Re: Joystick Help Please

Posted: Mon Mar 02, 2015 9:23 pm
by i_love_u
Kingdaro wrote:It's possible that your joystick isn't actually registered as a gamepad. Try putting this in your code (with console enabled in conf.lua):

Code: Select all

function love.joystickpressed(joystick, button)
   print(joystick, button)
end
Press buttons on your joystick, and if you get output, then that means you'll have to add gamepad mappings manually for your controller. See: love.joystick.setGamepadMapping.
Is "registered as a gamepad" and simply recognized by the following code the same thing?

Code: Select all

love.joystick.getJoystickCount()

Re: Joystick Help Please

Posted: Mon Mar 02, 2015 10:21 pm
by Kingdaro
No, they aren't. Joysticks and gamepads are conceptually different things. Rather, they have different workings in their API. Joysticks represent the controller itself, where the gamepad bindings, axes and such are there just so you have an easy to use, universal... thing, to more easily support multiple controllers. As an example, the button 1 differs widely from controller to controller, but different mappings for 'a' will always allow you to get the button you want as mapped on the controller itself.

In relation to your question, you can also check if a joystick is detected as a gamepad directly, something I forgot about when making my post. I'll also apologize if my explanation isn't all that clear, the wiki page here should give a good enough explanation as well.