Count the number of connected game controllers

Monkey Forums/Monkey Programming/Count the number of connected game controllers

chimaera(Posted 2014) [#1]
I was wondering if there is any way to find out how many game controllers that are connecrted. JoyX() and the other commands have supports more than one, but I do not know to find out how many are connected.

I am at a game jam, so I would really appreciate fast help! :)


ImmutableOctet(SKNG)(Posted 2014) [#2]
Unfortunately, I don't think Monkey supports detecting what's plugged in. If I remember right, this was because of an issue with the XNA target. You'll have to set it up manually by either checking for any button, or by checking for specific buttons. Either way, you'll have to log the state of each controller manually. And disconnection would effectively be the same.

But just because Monkey doesn't support it, that doesn't mean GLFW doesn't. So, assuming you're using one of the GLFW targets (Doesn't work with GLFW2; see below for a full example with GLFW2 support), you could do the following:


The 'JoyID' argument (Just 'joy' in GLFW) works like 'JoyX', it starts at controller zero. Though, Monkey (To my knowledge) doesn't currently support 16 controllers (Without some hacks), so 1-4 should be fine detection-wise. You might want to stick to those constants for the sake of compatibility. And in-fact, I should have made them globals, and just put them in the external area, but I wanted to show what they were.

And if you really wanted to (And I wasn't lazy), you could use my 'input' module, but that'd require code changes, not to mention myself putting in the work of setting it up on GitHub. If you were to do something like that, you'd get some added features relating to remapping.


ImmutableOctet(SKNG)(Posted 2014) [#3]
Here's a full example (With proper support for GLFW2):


EDIT: Updated the example to be a bit less GLFW specific for the sake of potential code changes.


chimaera(Posted 2014) [#4]
Thanks for the help!

Unfortunately we didn't have time to add this to our game, but I will check it out and might add it to the "post gamejam" release of the game.