boipushy icon indicating copy to clipboard operation
boipushy copied to clipboard

Add basic multiple controller support

Open volumia opened this issue 8 years ago • 2 comments

Adds really rudimentary multiple controller support.
You can use it as such:

local input = Input( { joystick_index = 1 } )
input:setJoystickIndex(2)

This hasn't gone through intensive testing, and doesn't cause an error if it gets a controller that doesn't exist (since it's possible that it might later).

volumia avatar Dec 02 '17 10:12 volumia

I literally don't have multiple controllers so I can't test this (unless there's a way to test with only 1 that I'm not aware of). That was the reason why I made it only for 1 so far.

I won't merge this in yet until I buy another controller and can test things further. But I'll leave this open and use this as the first tests I run when I get an additional one. The idea is to use setJoystickIndex to the relevant player before checking keypresses/down, right?

a327ex avatar Dec 03 '17 00:12 a327ex

In a nutshell, yeah. If I have a game where a bunch of players have to press the join button to enter the game, you'd set all the joysticks to their corresponding indexes and check from there.

local playerInputs = {}

for i = 1, 4 do
  local input = Input()
  input:setJoystickIndex(i)
  input:bind("fdown", "join")
  playerInputs[i] = input
end

function update()
  for _, input in pairs(playerInputs) do
    if input:pressed("join") then
      -- do player instantiation and input setting code here
    end
  end
end

This is partially the reason why setJoystickIndex doesn't cause any errors if a controller belonging to that index doesn't exist (yet).

edit: Oh, found a bug that is only relevant when using multiple controllers. Gonna go ahead and push this to my forked branch.

volumia avatar Dec 03 '17 12:12 volumia