Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a method to know if a joystick is plugged #5465

Closed
SuperUserNameMan opened this issue Jun 28, 2016 · 5 comments · Fixed by #5559
Closed

a method to know if a joystick is plugged #5465

SuperUserNameMan opened this issue Jun 28, 2016 · 5 comments · Fixed by #5559

Comments

@SuperUserNameMan
Copy link
Contributor

Operating system or device - Godot version:
Official 2.0.3stable and custom 2.1alpha

Issue description (what happened, and what was expected):

I've found no method to know if a joystick is already plugged.

The workarounds are :

  • scan device from 0 to 15 using Input.is_joy_known() ; but, if I understood correctly, it will only return true if the joystick has a mapping.
  • ask the player to press a button and capture the device number in event.

I would like to know in advance how many joysticks are already connected without asking to the players to press buttons.

Steps to reproduce:

Link to minimal example project (optional but very welcome):

@27thLiz
Copy link
Contributor

27thLiz commented Jun 28, 2016

Good catch.
Should we have a method that returns an array of connected device IDs or do you want to query the connection status of individual devices? Or maybe both ;)

@SuperUserNameMan
Copy link
Contributor Author

I think i'd be happy with any one of these two methods, so I guess that having both would be a bliss ^^

@27thLiz
Copy link
Contributor

27thLiz commented Jun 28, 2016

On a second thought, I think the first one will be enough.
With that, one can easily replicate the other one:

if device_id in Input.get_connected_joysticks():

@kakoeimon
Copy link

I used this method to find out if a joystick is plugged.
if Input.get_joy_name(0):

Without joystick Input.get_joy_name() returns an empty string which can be used in as false.

@SuperUserNameMan
Copy link
Contributor Author

@kakoeimon : oh thanks for the idea. I did not think of it !

27thLiz added a commit to 27thLiz/godot that referenced this issue Jul 5, 2016
@akien-mga akien-mga added this to the 2.1 milestone Jul 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants