Joystick Help Please

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
i_love_u
Prole
Posts: 28
Joined: Sat Nov 29, 2014 12:13 am

Joystick Help Please

Post by i_love_u » Mon Mar 02, 2015 9:05 pm

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?

User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Joystick Help Please

Post by Kingdaro » Mon Mar 02, 2015 9:20 pm

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.

User avatar
i_love_u
Prole
Posts: 28
Joined: Sat Nov 29, 2014 12:13 am

Re: Joystick Help Please

Post by i_love_u » Mon Mar 02, 2015 9:23 pm

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()

User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Joystick Help Please

Post by Kingdaro » Mon Mar 02, 2015 10:21 pm

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.

Post Reply

Who is online

Users browsing this forum: drfractal and 9 guests