gamepad_is_connected

This function will return whether a gamepad is connected to the given "slot" (returns true) or not (returns false).

Note that there may be a slight delay between the user connecting the gamepad and GameMaker detecting it as being connected (this is especially the case when dealing with bluetooth connected controllers).

NOTE On some platforms - especially consoles - this function may return false immediately after a gamepad has been connected/selected. It is recommended to instead use the Async System event to check when it's connected.

 

Syntax:

gamepad_is_connected(device);

Argument Type Description
device Real Which gamepad "slot" to check.

 

Returns:

Boolean

 

Example:

var _gamepad_count = array_length(gamepads);

for (var i = 0; i < _gamepad_count; i++)
{
    var _gamepad = gamepads[i];
    if (gamepad_is_connected(_gamepad))
    {
        // Read input
    }
}

The above code loops through the gamepads stored in the array gamepads. If any given gamepad is still connected, you can read input from it within the for loop.

This follows the Gamepad Movement example on Movement And Controls where the gamepads array is set up.