Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Add basic multiple controller support #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

volumia
Copy link

@volumia volumia commented Dec 2, 2017

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).

@a327ex
Copy link
Owner

a327ex commented Dec 3, 2017

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?

@volumia
Copy link
Author

volumia commented Dec 3, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants