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
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

I am using a xbox 360 controller, when I try to get the inputindex for any button using the Joystick:getGamepadMapping()function I always get nil results, the function Joystick:isGamepadDown() works fine tho. This is the code:

Code: Select all

	local inputtype, inputindex, hatdirection = joystick:getGamepadMapping("a")
	print("name", joystick:getName())
	print("is gamepad", joystick:isGamepad())
	print("inputtype", inputtype)
	print("inputindex", inputindex)
	print("hatdirection", hatdirection)

prints:
	name XInput Controller #1
	is gamepad true
	inputtype nil
	inputindex nil
	hatdirection nil
note the results of the function are nil :(

I tried different controllers, they are all original Xbox controllers. I am currently using Love version 0.10.2 but I tried different versions to see if it was a bug introduced recently but got the same results in all the versions I tried

any help would be truly appreciated :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 »

Returns nil if the Joystick isn't recognized as a gamepad or the virtual gamepad axis is not bound to a Joystick input.
I suppose no binding is present since it's a nondescript Xinput gamepad.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by Beelz »

With an Xbox 360 controller, you can use Joystick:isGamepad and the accompanying callbacks.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by zorg »

Beelz wrote:With an Xbox 360 controller, you can use Joystick:isGamepad and the accompanying callbacks.
That's the issue, that he can't; for some reason, his xbox360 controller gets reported as a generic one, as raidho said. And while :isGamepad returns true, the other function doesn't work.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
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:I suppose no binding is present since it's a nondescript Xinput gamepad.
what do you think could be the cause for this? the controller works fine with all my games and it works fine in LOVE too. The only issue I'm having is with the function getGamepadMapping. I tried to look for drivers, but the controller is plug and play, it should install the drivers automatically
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

Beelz wrote:you can use Joystick:isGamepad and the accompanying callbacks.
yes I can, and they work fine, but that's not what I am trying to do, I need to use the function getGamepadMapping.

Thanks to all the people that are trying to help, you are great! :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 »

sandygk wrote:what do you think could be the cause for this? the controller works fine with all my games and it works fine in LOVE too. The only issue I'm having is with the function getGamepadMapping. I tried to look for drivers, but the controller is plug and play, it should install the drivers automatically
Drivers are clearly present - otherwise it won't work at all. It's just drivers won't recognize it as XBox controller. Try installing controller-specific drivers.
User avatar
sandygk
Prole
Posts: 20
Joined: Mon Nov 28, 2016 9:22 pm

Re: joystick:getGamepadMapping(buttonName) always returns nil

Post by sandygk »

windows recognize the controller name without problems, apparently the drivers are not the problem, see attachment:
Attachments
Capture.PNG
Capture.PNG (12.7 KiB) Viewed 5196 times
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's possible there's a bug in getGamepadMapping. Can anyone else use it successfully? Does it work on different controllers?

What's the output of [wiki]Joystick:getGUID[/wiki] for you?
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 »

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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests