• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Making gamepad input work with every gamepad

D

Darren

Guest
How would I handle gamepad input in a single player game where I want every single gamepad connected to do the same thing, allowing the player to pick whichever gamepad they want?

I'm not sure how to specify the device in gml when I just want ANY gamepad to perform the action specified.

Thanks all.
 
D

Darren

Guest
Second hit on google:
https://www.yoyogames.com/blog/75/how-to-setup-and-use-gamepads

System events are very convinient for this; just keep in mind game restarts when you implement it.
This seems overly complicated for what I'm looking for and didn't solve my issue. I'm making a single player game, I just want that instead of specifying a device, any and all the gamepads connected to the pc perform the same action. I shouldn't even need a pad index because I want all gamepads to do the exact same thing.
 

samspade

Member
This seems overly complicated for what I'm looking for and didn't solve my issue. I'm making a single player game, I just want that instead of specifying a device, any and all the gamepads connected to the pc perform the same action. I shouldn't even need a pad index because I want all gamepads to do the exact same thing.
If it single player only, why does it need to register input from every connected gamepad rather than just the first? I think most single player games just ignore controllers after the first one, but I could be wrong. If you really wanted to do it anyway, you would likely want to set up a controller object and then loop through all possible gamepads checking for input. For example:

Code:
///step event of obj_input_controller

x_pushed = keyboard_check_pressed(vk_space);

for (var i = 0; i < max_controllers; i += 1) {

    x_pushed = x_pushed || gamepad_button_check_pressed(i, gp_face1);

}

///example use - some other step event or code

jump = obj_input_controller.x_pushed;
I can't remember if need to do something else first in order to read from multiple controllers or if it is automatic, if it isn't, you would need to set that up first. Otherwise, this is one way to assign multiple controllers to the same input (as further illustrated by showing that this accepts either the space bar or controller inputs).
 
D

Darren

Guest
If it single player only, why does it need to register input from every connected gamepad rather than just the first? I think most single player games just ignore controllers after the first one, but I could be wrong. If you really wanted to do it anyway, you would likely want to set up a controller object and then loop through all possible gamepads checking for input. For example:

Code:
///step event of obj_input_controller

x_pushed = keyboard_check_pressed(vk_space);

for (var i = 0; i < max_controllers; i += 1) {

    x_pushed = x_pushed || gamepad_button_check_pressed(i, gp_face1);

}

///example use - some other step event or code

jump = obj_input_controller.x_pushed;
I can't remember if need to do something else first in order to read from multiple controllers or if it is automatic, if it isn't, you would need to set that up first. Otherwise, this is one way to assign multiple controllers to the same input (as further illustrated by showing that this accepts either the space bar or controller inputs).
From the manual: The gamepad "slots" are indexed from 0 with slots 0 - 3 inclusive being 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.

So basically, I can't just check for the first slot, because it varies with the type of controller, if I understand correctly.
 

samspade

Member
From the manual: The gamepad "slots" are indexed from 0 with slots 0 - 3 inclusive being 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.

So basically, I can't just check for the first slot, because it varies with the type of controller, if I understand correctly.
The code I posted checks for as many gamepads as you choose, up though 12 (which I believe is the max) if you wanted. It's roughly the same system you would use to detect multiple touches on a multi-touch device. I haven't tested it, but I don't think it should throw an error to check slots that don't have a gamepad but I often have code running that checks for gamepad input on device 0 and there's no error even if I don't have a gamepad plugged in.
 
F

Finn

Guest
This seems overly complicated for what I'm looking for and didn't solve my issue. I'm making a single player game, I just want that instead of specifying a device, any and all the gamepads connected to the pc perform the same action. I shouldn't even need a pad index because I want all gamepads to do the exact same thing.
You only need the top part; you can ignore the rest.
If the player d/ced a device or plugged in a new one you probably want to be able to deal with that.
System events do most of the work for you really; I found it very convenient to use.
 
Top