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

If two or more controllers are connected they are considered the same controller #327

Open
Dukemz opened this issue Jul 18, 2024 · 7 comments
Assignees
Labels

Comments

@Dukemz
Copy link
Contributor

Dukemz commented Jul 18, 2024

image

If two controllers/gamepads of the same type/ID are connected, p5play treats them as the same (in the attached screenshot, they are both considered to be contros[0]).

image

I'm not completely sure why this happens? Possibly because gamepad index isn't taken into account?

@quinton-ashley
Copy link
Owner

What version of p5play are you using?

@Dukemz
Copy link
Contributor Author

Dukemz commented Jul 18, 2024

3.22.11, forgot to include in the post my bad

@quinton-ashley
Copy link
Owner

Thanks for reporting the issue but I don't know why it occurs.

Take a look at the _Contros._onConnect function:

p5play/p5play.js

Line 10563 in e587c7f

_onConnect(gp) {

The indexes of controllers in p5play's contros array differ from the HTML5 navigator.gamepads array because I wanted reconnected controllers to be at the same index in the contros array and new controllers should be added to the next available slot in the controllers array (if previous controllers were removed).

If contros[0] already exists it shouldn't be possible to overwrite it. Can you try to set breakpoints in p5play.js to see why index is still 0 when the second controller is added?

@Dukemz
Copy link
Contributor Author

Dukemz commented Jul 29, 2024

The second time the _onConnect function is called it seems that this is an array with just 1 object
image
which as a result causes index to be 0.
Looking at the MDZN documentation, it says that controllers that are disconnected will be replaced in the array returned by navigator.getGamepads() with null, but will remain in the same index.
image
I'm still not entirely sure what's going on but I'll reply again when I've figured out some more details.

@Dukemz
Copy link
Contributor Author

Dukemz commented Jul 30, 2024

image
This seems to be the most reliable fix. The index should stay the same between disconnects/reconnects.
Edit: see below comment

@Dukemz Dukemz changed the title If two controllers of the same type are connected they are considered the same controller If two or more controllers are connected they are considered the same controller Oct 22, 2024
@Dukemz
Copy link
Contributor Author

Dukemz commented Oct 22, 2024

Bug still present in 3.23. Putting what Quinton said on the p5play discord server here for anyone not in the server.
image

@quinton-ashley
Copy link
Owner

@Dukemz I will take another look at this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

No branches or pull requests

2 participants