How to configure the joypad?

Started by Diarandor, August 21, 2015, 11:43:36 PM

Previous topic - Next topic
August 21, 2015, 11:43:36 PM Last Edit: August 22, 2015, 02:08:38 AM by Diarandor
Hi! I am using a joypad of microsoft (of the Xbox360). I would like to set a default configuration like this:
A = "attack", B = "action", X = "item_1", Y = "item_2", Start = "pause", Analog-stick = directions.

The start button and the analog stick work by default as I want. What should I do to set the behaviour of the other keys to call the corresponding commands? Is there already some example to do this? (I would like to associate the buttons of the joypad to the commands, avoiding to define a casewise function on_key_pressed(key), if possible.)

I have read the Lua API but I did not find a short way to do it. Also, I don't know which "keys" are the ones associated to the buttons A,B,X,Y. Could you help me?  :-\
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

There is no way to programmatically know joypad button names as the user sees them ("A", "Start", and others). What SDL gives us is only "button 1", "button 2", etc. I believe this is the same with other frameworks than SDL.

So you need a menu to let the user configure commands. game:capture_command_binding is handy to do that. See the one of zsdx for example.

Thanks a lot! It worked. Currently, I am using just:

-- Configure some joypad buttons.
game:set_command_joypad_binding("action", "button 10")
game:set_command_joypad_binding("attack", "button 11")
game:set_command_joypad_binding("item_1", "button 12")
game:set_command_joypad_binding("item_2", "button 13")

Although, as you say, the number of the keys will be different for other joypads. (But maybe this works for all microsoft joypads.)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Sorry for the necropost

I would also like to do this? Does this require a .lua file in a specific folder or altering an existing .lua file?