Page 1 of 2

A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 12:48 am
by i_love_u
I am using a corded black Xbox 360 controller:

(1) Is there not a button(s) for the left/right triggers?
https://love2d.org/wiki/GamepadButton

(2) What is the 4th argument supposed to be?
https://love2d.org/wiki/love.joystick.setGamepadMapping

Code: Select all

success = love.joystick.setGamepadMapping( guid, button, inputtype, inputindex, hatdir )
(3) If I use the following code:

Code: Select all

if joystick:isGamepadDown("start") then
    --code
end
It responds to the "back" button...

(4) If I use the following code:

Code: Select all

if joystick:isGamepadDown("rightstick") then
    --code
end
It responds to the "leftstick" button...

(5) If I use the following code:

Code: Select all

if joystick:isGamepadDown("leftshoulder") then
    --code
end
It responds to "rightstick"....

(6) The whole d-pad doesn't respond, nor have I even tried the analog sticks. Here is my code in the love.load():

Code: Select all

	joysticks = love.joystick.getJoysticks()
	joystick = joysticks[1]
	love.joystick.setGamepadMapping( joystick:getGUID(), "a", "button", 1, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "b", "button", 2, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "x", "button", 3, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "y", "button", 4, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "back", "button", 5, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "guide", "button", 6, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "start", "button", 7, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "leftstick", "button", 8, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "rightstick", "button", 9, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "leftshoulder", "button", 10, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "rightshoulder", "button", 11, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "dpup", "button", 12, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "dpdown", "button", 13, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "dpleft", "button", 14, nil )
	love.joystick.setGamepadMapping( joystick:getGUID(), "dpright", "button", 15, nil )
Any help would be greatly appreciated! :awesome: :crazy: :huh: :cool: :o: :3

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 2:01 am
by Clavus
I haven't played with this myself that much, but you can use love.joystick.loadGamepadMappings to load SDL's gamecontrollerdb.txt and instantly support a variety of gamepads. Maybe that will help with your mapping issue?

And the trigger buttons are usually mapped to an axis so use Joystick:getAxes to get their values.

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 2:41 am
by slime
Since you're using an Xbox 360 controller, you shouldn't need to set any mappings yourself – SDL has a built-in collection of mappings that includes Xbox 360 controllers.
Your code might be remapping things to the wrong values (different drivers and controllers use different joystick button values for the same physical buttons, which is one reason why the gamepad API exists.)

You can check by calling [wiki]Joystick:isGamepad[/wiki] and/or [wiki]Joystick:getGamepadMapping[/wiki] before any of your love.joystick.setGamepadMapping calls are executed.

Also be sure to use LÖVE 0.9.2 if you really do need to use setGamepadMapping, since it had a number of bugs in 0.9.1.

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 4:27 am
by i_love_u
slime wrote:Since you're using an Xbox 360 controller, you shouldn't need to set any mappings yourself – SDL has a built-in collection of mappings that includes Xbox 360 controllers.
Your code might be remapping things to the wrong values (different drivers and controllers use different joystick button values for the same physical buttons, which is one reason why the gamepad API exists.)

You can check by calling [wiki]Joystick:isGamepad[/wiki] and/or [wiki]Joystick:getGamepadMapping[/wiki] before any of your love.joystick.setGamepadMapping calls are executed.

Also be sure to use LÖVE 0.9.2 if you really do need to use setGamepadMapping, since it had a number of bugs in 0.9.1.
I did joystick:isGamepad() and it returns false. But, my face buttons still work (a, b, x, y). I also did the Joystick:getGamepadMapping, and it returns nil for all 3 return values. Do I just need to get a new controller?

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 5:56 am
by slime
Weird. What OS are you using and what does Joystick:getGUID return exactly? Is it an official xbox 360 controller or some aftermarket variant?

If you use this with [wiki]love.joystick.loadGamepadMappings[/wiki], does it work?

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 03, 2015 10:48 pm
by i_love_u
slime wrote:Weird. What OS are you using and what does Joystick:getGUID return exactly? Is it an official xbox 360 controller or some aftermarket variant?

If you use this with [wiki]love.joystick.loadGamepadMappings[/wiki], does it work?
Windows 7. I got the controller new from Walmart. Its should be official. I am looking at the "devices and printers" section in my control panel, and it is recognized as "Xbox 360 Controller for Windows". The GUID is 5e048e02000000000000504944564944.

I am using that line of code:

Code: Select all

love.joystick.loadGamepadMappings( "gamecontrollerdb.txt" )
And it is giving me this error code:
attempt call field 'loadGamepadMappings' (a nil value)

Re: A Bunch Of Joystick Questions

Posted: Wed Mar 04, 2015 12:11 am
by Kingdaro
Are you not using love 0.9.2? If not, uninstall your current version and download the latest from the website.

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 24, 2015 8:47 pm
by undef
Actually it seems to be a bug in love 0.9.2.
Gamepad works with my game in love 0.9.1 but it doesn't work correctly in 0.9.2.

Try for yourself with the .love I uploaded, all the buttons have different numbers now and the dpad doesn't work at all.

Re: A Bunch Of Joystick Questions

Posted: Tue Mar 24, 2015 9:46 pm
by slime
undef wrote:Actually it seems to be a bug in love 0.9.2.
Gamepad works with my game in love 0.9.1 but it doesn't work correctly in 0.9.2.

Try for yourself with the .love I uploaded, all the buttons have different numbers now and the dpad doesn't work at all.
That's not really related to the original post (and not a bug) – LÖVE 0.9.2 uses a more recent version of SDL2 which interprets XInput controllers (e.g. xbox 360 controllers) differently. The d-pad on XInput controllers in Windows is now treated as a hat (via [wiki]love.joystickhat[/wiki]) if you aren't using the gamepad API.

You should be using the gamepad API though!

Code: Select all

local button = "no button pressed"

function love.draw()
    love.graphics.print(button)
end

function love.gamepadpressed(joystick, gamepadbutton)
    button = gamepadbutton
end

i_love_u's issue seems to be that the controller being used isn't recognized as an XInput device by SDL.

Re: A Bunch Of Joystick Questions

Posted: Wed Mar 25, 2015 2:28 am
by undef
Oh, there is a love.gamepadpressed.
Pity I didn't notice that earlier^^
Thanks!