XBOX One gamepad detected in slot 0 but no input detected in Game Maker Studio 2

I am following along this udemy course and in the section where we implement a very simplistic gamepad support, I am unable to make my XBOX One controller work as demonstrated in the lecture. Here is the get_input() script with both keyboard support (which works fine when there is no controller connected) and gamepad support.

//keyboard input
left = keyboard_check(vk_left);
right = keyboard_check(vk_right);
up = keyboard_check(vk_up);
down = keyboard_check(vk_down);
attack = keyboard_check_pressed(vk_shift);
jump = keyboard_check_pressed(vk_space);
jump_held = keyboard_check(vk_space);
block = keyboard_check(ord("Z"));

//controller input
var _dev = 0;
if gamepad_is_connected(_dev) {
    var _deadzone = 0.3;
    left = gamepad_axis_value(_dev, gp_axislh) < -_deadzone;
    right = gamepad_axis_value(_dev, gp_axislh) > _deadzone;
    up = gamepad_axis_value(_dev, gp_axislv) < -_deadzone;
    down = gamepad_axis_value(_dev, gp_axislv) > _deadzone;
    attack = gamepad_button_check_pressed(_dev, gp_face2);
    jump = gamepad_button_check_pressed(_dev, gp_face1);
    jump_held = gamepad_button_check(_dev, gp_face1);
    block = gamepad_button_check(_dev, gp_shoulderr);
}

I know that my gamepad is detected because when I run this code:

var numPads= gamepad_get_device_count();
for(var i = 0; i < numPads; i++;)
{
    if(gamepad_is_connected(i)) show_message(string(i) + ": " + gamepad_get_description(i));
}

I get a message saying "0: XInput STANDARD GAMEPAD". However, when I launch the game and try to use the buttons or the joystick, nothing happens. I tried using two different XBOX One controller but I have the same problem. When I try with my gamecube controller connected using a Mayflash GC Controller Adapter on slot 4, it works. Am I missing something specific about XBOX One controllers? I think that in the course the teacher uses an XBOX 360 controller, which I don't have.

Please send help!

Upvotes: 0

Views: 1212

Answers (1)

Steven
Steven

Reputation: 2122

I've last month tried to implement Controller support using an XBox One Controller, and I got it working just fine. Also with using gamepad_button_check() and gamepad_axis_value() and the other variables I've used from this link: https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/controls/gamepad%20input/index.html

I use both gamepad_is_supported and gamepad_is_connected in the gamepad code to make sure it has found a gamepad.

It should be possible to work with an XBox One Controller.
So maybe the problem is something out of the box. (e.g. Have you checked the Controller is installed on your PC? Or is the connection only in the Create Event, and that it doesn't update when your controller is plugged in?)

Upvotes: 1

Related Questions