how do you check if a gamepad is connected
I don't know how you check if a gamepad is connected, do you use an "if" statement or what?
I don't know how you check if a gamepad is connected, do you use an "if" statement or what?
Ask the user to indicate the device they want to control, when they select the gamepad icon, ask them to confirm their choice with a button. Check if new fields appear in the gamepad object. If so, you have a gamepad connected.
update = function()
for field in gamepad.press
print(field + " : " + gamepad.press[field])
end
for field in keyboard.press
print(field + " : " + keyboard.press[field])
end
end
See that there are more fields after pressing the keys. I don't have a gamepad for testing, but it's possible that in this object there will also be additional fields after each first press of the button.
The second option is to add code in JavaScript and receive information about gamepad connection events.
https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API
window.addEventListener("gamepaddisconnected", (e) => {
console.log(
"Gamepad disconnected from index %d: %s",
e.gamepad.index,
e.gamepad.id,
);
});