Gamepad not working

Eik

Member
Hello! I have been trying to implement gamepad controls to my game, however, It seems like GameMaker cant detect any input on the controller

to demonstrate I'm using this code:


show_debug_message(gamepad_button_check(0, gp_face1))


(don't know if this counts but I'm using a ps4 controller)
 

FrostyCat

Redemption Seeker
What made you think the controller you plugged in is number 0? The Manual entry for gamepad input clearly says it is not always the case.
GameMaker Studio 2 has a number of dedicated functions that can be used to detect both analog and digital controls from multiple connected gamepads. These functions work similar to the Device Inputs, in that you can detect up to four different XInput game pads that are connected (and up to 8 DirectInput gamepads) and deal with the input from each one using the same functions. Note that when a gamepad is plugged in to your device (or it is removed) then an asynchronous System Event is triggered where you can deal with the situation using the appropriate functions.

The gamepad "slots" are indexed from 0 upwards, and the actual slot that a gamepad assigned will depend on a variety of factors, not least of which is the OS that the project is running on. On the Windows target, slots 0 - 3 inclusive are only for Xinput gamepads, ie: Xbox360 controllers and compatibles. However you can also check slots 4 - 11 inclusive for DirectInput gamepads, which means you can detect many other models of controller when connected through these slots. On other platforms, pads may be detected on any slot that the OS has assigned it, which could slot 3 or slot 20 or more. For example, Android devices will store bluetooth gamepads in a slot and then reserve that slot for that gamepad in the future, whether it is connected or not, so you cannot assume that a single connected gamepad is connected to slot 0, as this will probably not be the case.
 
Top