Legacy GM [SOLVED] Gamepad not detected during runtime?

Mr Errorz

Testing gamepad support on a GMS 1.4 project, it seems that if I unplug my gamepad during runtime and than plug it back in,
it doesn't always gets detected...

I tested in 2 ways and got varying results-
If I hit compile to run the game while the gamepad is connected to the PC [meaning the game starts while a gamepad is connected], it seems to never detect it if I plug it back after disconnecting.

If I hit compile to run the game while the gamepad is NOT connected to the PC [meaning the game starts without a gamepad being connected],
when I plug a controller after the game starts, it detects the gamepad, but than falters sometimes when I unplug/plug again.

Anyone knows why this is happening or how to work around it?
Mainly, it seems as if gamepad_is_connected() doesn't always detect a gamepad being connected...


Do you check on what port the newly plugged-in gamepad is being registered? Sometimes this changes the "device slot" when re-plugging. Resulting in the gamepad having another port.

An easy (and a bit crude) way to do that is to make a loop checking for any input on all possible ports.

    /// checking controllers for input and registers that one as
    /// the input controller from there onward
        var _input_val = 0;
    for (var _controller_nr = 0 ; _controller_nr < 4 ; _controller_nr++) {
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_face1));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_face2));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_face3));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_face4));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_shoulderl));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_shoulderlb));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_shoulderr));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_shoulderrb));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_select));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_start));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_stickl));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_stickr));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_padu));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_padd));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_padl));
            _input_val += abs(gamepad_button_check_pressed(_controller_nr , gp_padr));
        if (_input_val > 0) {
            _controller_nr    = 4; /// stops loop from checking the other controllers ports
            device_nr        = 0; /// saves the davice_nr of the "new" controller best save this in a global variable or on a permanent object

Mr Errorz

oops, checked it on another PC and it worked well, guess my USB connectors are a bit dodgy on my main PC or something.
Sorry, false alarm.