joystick:getGamepadMapping(buttonName) always returns nil

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
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by slime »

raidho36 wrote:The getGamepadMapping goes down to according SDL function, if there's a bug it's in SDL. Pretty sure though it's just SDL can't pick up the controller as XBox gamepad for whatever reason.
love does some parsing of the SDL mapping string inside getGamepadMapping. There may be a bug in that. In the first post it was already determined that SDL does recognize it as a gamepad (the SDL_GameController API does recognize it), and apparently the input callbacks work.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by raidho36 »

It will only return nil if SDL_GameControllerMappingForGUID fails or if its returned mapped string doesn't contains the requested input map. So either mapping for that GUID does not exist altogether, or it's empty (since standard map is requested, i.e. it can't be absent from valid standard mapping).
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

slime wrote:What's the output of [wiki]Joystick:getGUID[/wiki] for you?

Code: Select all

print(love.joystick.getJoysticks()[1]:getGUID())

prints:
	78696e70757401000000000000000000
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

I remember reading that SDL uses this list for mapping:

https://github.com/gabomdq/SDL_GameCont ... llerdb.txt.

If that's the case, my GUID (78696e70757401000000000000000000) does not appear in the list, and there is no entry for Xbox controller for windows in the list which is weird.

Could anyone confirm that this is the default map used by SDL and Love?

Thanks for the help :awesome:
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by slime »

It doesn't use that list by default, although you can make use of it with [wiki]love.joystick.loadGamepadMappings[/wiki].

SDL uses an internal list inside its source code by default: https://github.com/spurious/SDL-mirror/ ... erdb.h#L32

I'm not sure what's up with your GUID. SDL may have changed its XInput controller GUIDs without changing the mapping string in the file above, possibly.
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

slime wrote:SDL uses an internal list inside its source code by default: https://github.com/spurious/SDL-mirror/ ... erdb.h#L32.
That makes more sense. My GUID does not appear in this list either, but maybe it's not supposed to appear. My controller is recognized as a XInput Controller by LOVE, that's what getName() returns. Maybe it should fall under this case, note that no GUID is used in this case.

Code: Select all

static const char *s_ControllerMappings [] =
{
#if SDL_JOYSTICK_XINPUT
"xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
#endif	
...
this code is from the link above.

BTW sorry for my English, is far from good.
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

can someone check if getGamepadMapping is working with a xbox controller? It does not matter if it is wired or wireless (I have both types to test).
It will be good to know what value of getGUID() do you get for your xbox controller?
and what name do you get from getName()?
this is the code I would like you to test, with a Xbox controller plugged in:

Code: Select all

local joystick = love.joystick.getJoysticks()[1]
local a,b,c = joystick:getGamepadMapping("a")
print(a,b,c)
print(joystick:getGUID())
print(joystick:getName())
this code for me prints:

Code: Select all

nil	nil	nil
78696e70757401000000000000000000
XInput Controller #1
thanks in advance you are the best :awesome:
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by raidho36 »

Linux here; mine is recognized as

Code: Select all

nil	nil	nil
030000005e0400008e02000014010000
Microsoft X-Box 360 pad
Still no mappings though.
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

raidho36 wrote:Still no mappings though.
then it is not just me with the nil result.

I think that for an Xbox controller getName is expected to return "Xbox Controller #x" in windows, can somebody confirm if this is the case?
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by slime »

"XInput Controller" is correct for a 360 gamepad on Windows. I just tested (on Windows) with my 360 controller and it returns nil for getGamepadMapping as well, even though [wiki]love.gamepadpressed[/wiki] and related gamepad functionality still works as expected.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests