• 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!

Linux Gamepad Code Don't Works on Ubuntu

C

CleanWater

Guest
Hi there!

Sorry for my bad English and sorry for posting it again here, I posted before in the Legacy forums, but I think I posted in the wrong place.

This code below runs fine on Windows, but I'm having a lot of issues to have my gamepad working on Linux with the same code:

Code:
///Checking Gamepads that are connected
var _gpNum = gamepad_get_device_count();
var _temp;
for (_temp = 0; _temp < _gpNum; _temp++;){
    if (gamepad_is_connected(_temp)){
        pad_index[_temp]= true;
        gp_index = _temp;
    }
    else{
        pad_index[_temp]= false;
    }
}
if (gamepad_is_connected(gp_index)){
    gp_var = true;
    if (jsdefault_var == true){
        jsbutton_var[1] = gp_face1;
        jsbutton_var[2] = gp_face3;
        jsbutton_var[3] = gp_start;
        jsbutton_var[4] = gp_face4;//DLC
    }
    else{
        jsbutton_var[1] = jsbutton_var[1];
        jsbutton_var[2] = jsbutton_var[2];
        jsbutton_var[3] = gp_start;
        jsbutton_var[4] = jsbutton_var[3];//DLC
    }
}
else{
    gp_var = false;
}
My GM version is 1.4.1772 and I'm using a D-Input gamepad on Ubuntu 16.06.

I managed to play test the game with the gamepad using this code before, but now, the game recognizes that there's a gamepad inserted, but pressing any button on it have no effect in-game.

I don't know what's going wrong there! Can someone help me?
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Don't use the device_count function like this. It only tells you how many pads are added, but NOT which slot they are actually connected to. Instead either use the system event to find out the pad slots and store them in a list or an array or something, or simply make the for loop check slots 0 to 11 for a pad. See this tech blog: https://www.yoyogames.com/blog/75/how-to-setup-and-use-gamepads (it's for GM:S 1.4, but it should all work exactly the same in GMS2).
 
C

CleanWater

Guest
Hey, many thanks @Nocturne !

I downloaded the example and playtested it, but the problem remains the same: The gamepads are detected, but they don't detect the button input.

Here's a screenshot of the debug on linux.


For both gamepads, pressing the Axis had no change in the values in the Linux play test.
On Windows, from Left H Axis to Right V Axis, they all changed from 1 to -1 when rotating the gamepad's sticks as expected.

Edit: It just occurred to me that the variables gp_face1, gp_face2, and all the other gamepad input variables might be returning different values on Linux than it returns on Windows.

Could it be the cause of this lack of responsiveness?

How can I get the value of the buttons being pressed to confirm this?
 
Last edited:
C

CleanWater

Guest
So, after some trials and errors, I discovered three things!

1 - On Linux, the values of the buttons starts from 0 instead of 32769 (i.e.: The A button maps as 32769 on Windows, but 0 on Linux, and so goes on);
2 - All the code to check game pad inputs is working fine, but only in the Draw Events.
3 - On Windows, you can map to A button (and onward) with both 0's and 32769's values.

I didn't managed to get the values for the Axis Sticks on Linux.

Side Note: Somehow, the debug screen I created, started to crash on Windows, but not on Linux, for no reason at all.

I feel I'm getting close to solving this problem, so I still would like to get any clues from anyone interested in seeing the game pads working on Linux smoothly.
 
B

BabyDukaCPH

Guest
Hey CleanWater

I'm porting to Linux as well and I am experiencing some bad gamepad behaviour. I find it hard to find support for Linux controls in general in tge GM forums. I wonder if you have worked out a solution to make gamepad controls made for Windows compatible with Linux. Is there a logical fix to this incompatibility?

Also I noticed my players can't press and hold the control button while using the arrow keys. It seems that they can't press two buttons at the same time, in general. Have you encountered this issue too?

Any advice would be appreciated. Thanks a lot!
 
C

CleanWater

Guest
Hi there!

No, I didn't found an easy solution. I heard of some developers that programmed their own custom .dll for this, but I don't know to program in C++ or anything else, so I didn't managed to fix it by my own.

I also noticed similar issues with the keyboard, but I think it's a problem from certain keyboards, related to the circuit board or something like that.

My advice would be to not create games with "gamepad based gameplay", like platformers and such, if you are planning to port to Linux as well. :cool:
 

Zixtix

Member
Hello,

I have encountered issues with getting gamepads to work on Ubuntu as well. However, I found that if the export uses the Steam SDK and launched through Steam, each gamepad plugged in will register two gamepad slots with the game. The extra one's gamepad_get_description() will return as "Valve Streaming Gamepad", and this one can correctly respond to controller input.

Hope this helps!
 

Zixtix

Member
Also, if you use the beta runtime Version 2.2.1.273 of GMS 2, this issue seemed to have been addressed there.
 
C

CleanWater

Guest
Also, if you use the beta runtime Version 2.2.1.273 of GMS 2, this issue seemed to have been addressed there.
My thanks, I'm not using the GMS2 so soon due to business reasons (my target audience can't run games made with this engine) but thanks for sharing. =)
I'll do some testings here again to see if I can figure a solution out of this.
 
Last edited:
C

CleanWater

Guest
Just wanted to let everyone knows that the last update (1.4.9999) solved the majority of these issues I complained.

The only problems now are:
1 - Two D-Input controller models I have works fine on Windows, but only one of them works on Linux.
2 - For some reason, the gp_axislv is not registering any value on Linux.

I didn't had the opportunity to test X-Input controllers yet, so I don't know if it's a problem on the D-Input controllers, the OS, GM, or maybe there might be a workaround for it that I didn't figured out yet.
 
Top