GMS 2 Problems with GamePad Input in a Platform Game

Hi, I have some issues with my horizontal movement code.

I have a global variables in the Step Event of my object Player for the horizontal move:

global.input_key_left = keyboard_check(vk_left) || gamepad_axis_value(0, gp_axislh) < -0.5 || gamepad_button_check(0,gp_padl);
global.input_key_right = keyboard_check(vk_right) || gamepad_axis_value(0, gp_axislh) > 0.5 || gamepad_button_check(0,gp_padr);


And I want to call it in the same Step Evcent for action with this code:

//////////////////
// MOVING
//////////////////

if (global.input_key_left) //and state!=jump
{

if state!=jump && state!=ladder && state!=fall
{
state=run
xspd=-3;
framerate=0.5
sprite_index=spr_plr_Run
}
}

if (global.input_key_right) //and state!=jump
{

if state!=jump && state!=ladder && state!=fall
{
state=run
xspd=3;
framerate=0.5
sprite_index=spr_plr_Run
}

}

The problem is that the code works with the keyboard and not with the joystick or any Gamepad Input.
What I'm doing wrong?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Depending on gamepad type, the first gamepad you connect might not get index 0. (XInput on 0-3 and DInput on 4-11 on Windows, enumeration starting at 1 on Android, and completely random ranges on Ubuntu). There's an asynchronous event when a gamepad is connected or disconnected that gives you its ID, try storing that in a global variable and use that rather than a hardcoded 0.
 
Are you checking, in code, to see if the gamepad is connected?
Yes, the Gamepad is connected, the A Button is working (jump button), but when I run the code the player doesn't move, if I use the keyboard keys there's no problem.

Depending on gamepad type, the first gamepad you connect might not get index 0. (XInput on 0-3 and DInput on 4-11 on Windows, enumeration starting at 1 on Android, and completely random ranges on Ubuntu). There's an asynchronous event when a gamepad is connected or disconnected that gives you its ID, try storing that in a global variable and use that rather than a hardcoded 0.
Yes I check and the index is 0, but I don't know why the player doesn't move
 

kburkhart84

Firehammer Games
Try outputting to a debug message(or draw text on your screen in the game) of the result of the function gamepad_axis_value(0, gp_axislh). See if it is changing or not. That will at the least eliminate if that specific function is the issue or if it is elsewhere.

If indeed it is that specific function that is not working(and you already stated that the A button works so the gamepad is connected in theory), then I would need to see the code you are using for the A button...and need to know what OS you are using and what type of gamepad it is.
 

gnysek

Member
In above code I don't see any part of code to be used for checking against keyboard/gamepad, but I'm just thinking that if A for jump works, maybe you're using function to check if key is pressed instead of key held down to move left/right.
 
Top