A Bunch Of Joystick Questions

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.
User avatar
i_love_u
Prole
Posts: 28
Joined: Sat Nov 29, 2014 12:13 am

A Bunch Of Joystick Questions

Post by i_love_u » Tue Mar 03, 2015 12:48 am

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

User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: A Bunch Of Joystick Questions

Post by Clavus » Tue Mar 03, 2015 2:01 am

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.

User avatar
slime
Solid Snayke
Posts: 2858
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: A Bunch Of Joystick Questions

Post by slime » Tue Mar 03, 2015 2:41 am

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.

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

Re: A Bunch Of Joystick Questions

Post by i_love_u » Tue Mar 03, 2015 4:27 am

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?

User avatar
slime
Solid Snayke
Posts: 2858
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: A Bunch Of Joystick Questions

Post by slime » Tue Mar 03, 2015 5:56 am

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?

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

Re: A Bunch Of Joystick Questions

Post by i_love_u » Tue Mar 03, 2015 10:48 pm

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)

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

Re: A Bunch Of Joystick Questions

Post by Kingdaro » Wed Mar 04, 2015 12:11 am

Are you not using love 0.9.2? If not, uninstall your current version and download the latest from the website.

User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: A Bunch Of Joystick Questions

Post by undef » Tue Mar 24, 2015 8:47 pm

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.
Attachments
gamepad.love
Just start the love and your gamepad and see what button has which number when you press it.
(260 Bytes) Downloaded 63 times
twitter | steam | indieDB

Check out quadrant on Steam!

User avatar
slime
Solid Snayke
Posts: 2858
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: A Bunch Of Joystick Questions

Post by slime » Tue Mar 24, 2015 9:46 pm

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.

User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: A Bunch Of Joystick Questions

Post by undef » Wed Mar 25, 2015 2:28 am

Oh, there is a love.gamepadpressed.
Pity I didn't notice that earlier^^
Thanks!
twitter | steam | indieDB

Check out quadrant on Steam!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests