Page 1 of 1

Joystick revamp tutorials?

Posted: Wed Jan 29, 2014 12:35 am
by Form
I've been using Löve for a while now, and I recently switched to 0.9 for the Global Game Jam, but unfortunately I had to switch back to 0.8 because of the joystick revamp. The wiki provides a list of functions I can use with joysticks, but whenever I call them I get a nil value. So, for example, these lines:

Code: Select all

function love.update(dt)	
68	function playerINPUT( )
69		if love.joystick:getAxis(1) > 1 then 
70			ActorX[1] = ActorX[1] + 1 
71		end
72	end

	playerINPUT( ) 
end
Will return:

Code: Select all

Error
main.lua:69: attempt to call method getAxis (a nil value)
Now, I'm not used to an object oriented mindset, I'm used to thinking in an imperative/structured way. Is there something I'm not understanding about the new object based joysticks in 0.9?

I'm running the default debian package off of the main Love2d website (not the ppa), running off of Ubuntu 12.04, using XboxDRV for my 360 controller drivers.

Re: Joystick revamp tutorials?

Posted: Wed Jan 29, 2014 3:30 am
by Kingdaro
You are to use the joystick API to create new joystick objects via love.joystick.getJoysticks(), which returns a table of all of the connected joysticks (as joystick objects), which you are to call said functions upon, but not on the entire module itself.

Example:

Code: Select all

local joysticks = love.joystick.getJoysticks()

function love.draw()
  for i,j in pairs(joysticks) do
    love.graphics.print(j:getName(), 10, 10 + (i - 1)*20)
  end
end