PS3 Controller joysticks sticks

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

PS3 Controller joysticks sticks

Post by McPandaBurger »

Hi guys,

I'm trying to use my PS3 controller as an input device.

I found this thread viewtopic.php?f=5&t=618&p=5980&hilit=analogue#p5980

And it seems that there is some way to see what buttons constants are but I can't seem to find it on the wiki.

What I mean is, the X,circle, square and so on buttons seem to be a number between 1 and 19 which I found out from trial and error along with the numbers for all the other buttons, I can't seem to work out how to use the sticks,

this returns 0 : AxisNumber = love.joystick.getNumHats(1);
also zero: balls = love.joystick.getNumBalls(1)


So I'm a bit confused as how you find out what to put in: buttonDown = love.joystick.isDown(1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23); to identify that the sticks are being used.

I understand from reading around the web that the should go from 1 to -1 in each axis, which is exactly the control I'm after.

any examples of what to do would be really helpful or even if you know of a gizmo that points me in the right direction would be cool.

I'm Guessing I'm just being a plum and missing something really obvious as there doesn't seem to be too many people with this issue or similar on this forum, but feel free to point out my stupidity anyway, all part of the learning curve I guess.

thanks for your time in advance and sorry if I've missed a thread that answers this already (I looked all afternoon, but haven't come across much that helps).
I have no idea what I'm doing
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PS3 Controller joysticks sticks

Post by bartbes »

You are missing something obvious.

And why are you calling isDown with so many parameters? It return if any is down, so this would give you an amazing amount of lack of information.
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: PS3 Controller joysticks sticks

Post by McPandaBurger »

Thanks for the reply dude, I tried that before I posted, which is why I know it knows they are there. the trouble is it simply returned how many there were (as its name suggests) which is 4 (which makes sense up/down on both and left/right on both), but what it doesn't tell me is how to register if they are used.

the .isDown having all those numbers in was simply so I could test that all the buttons were working, which they are.


see here from the wiki:



anyDown = love.joystick.isDown( joystick, button1, button2, button3, ... )
Arguments

number joystick
The joystick to be checked
number buttonN
A button to check
Returns

boolean anyDown
True if any supplied button is down, false if not.


I can successfully map all the buttons, but I can't get my head around what they are called, for example in the thread I linked to in my last post, it looked like an xbox controller puts them down as "axe 1" and so on but that doesn't work as .isDown only wants a number from what I can tell. (I tried, 1-4 and none of them are right, I tired A1-A4 and none of those work either.)


I'm definitely being a gibbon, but I'm not sure how.
I have no idea what I'm doing
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PS3 Controller joysticks sticks

Post by bartbes »

Aww, I messed my link, I meant to link to love.joystick.getAxis.
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: PS3 Controller joysticks sticks

Post by McPandaBurger »

Tried that as well but I'm not sure what to put in the Axis part

Code: Select all

direction = love.joystick.getAxis( joystick, axis )
So my joystick is definately 1 so I have:

Code: Select all

direction = love.joystick.getAxis(1, axis )
but I'm not sure what to put in axis, 1, 2 don't work and it won't except X and Y as they are letters. it is safe to say I R TEH STUMPED :ultrashocked:
I have no idea what I'm doing
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PS3 Controller joysticks sticks

Post by bartbes »

You could try this.
Attachments
joy.love
(584 Bytes) Downloaded 245 times
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: PS3 Controller joysticks sticks

Post by McPandaBurger »

you're gonna hate me in a minute, but yeah I found that too, that's where I got the A1-A4 Idea, but it seems that it doesn't like it coz it's not a number. I haven't been able to find the source for that little script either as that's have the answer in there. I'm so close yet so far. Sad times man, Sad times.
I have no idea what I'm doing
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PS3 Controller joysticks sticks

Post by bartbes »

I made that, and the source is in there.. anyway, it should tell you which axes are what.
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: PS3 Controller joysticks sticks

Post by McPandaBurger »

oh right I changed the .love to a .zip and got the main.lua so cheers for that, now to figure out what it is you're doing, good stuff though dude, As you can tell I'm new to this, so the going is slow. What would help if you have time, is to put in a few comments on your code below so I can get the idea behind what you're doing and why, if you don't have time no worries I can work out, just interesting to see why you did what you did.

Code: Select all

state = {}

function love.load()
	love.graphics.setFont(love.graphics.newFont())
end

function love.update()
	for joy = 1, love.joystick.getNumJoysticks() do
		local j = state[joy]
		if not j then
			state[joy] = {}
			j = state[joy]
			j.name = love.joystick.getName(joy)
			j.axes = {}
			j.numAxes = love.joystick.getNumAxes(joy)
			for axis = 1, j.numAxes do
				j.axes[axis] = 0
			end
			j.buttons = {}
			j.numButtons = love.joystick.getNumButtons(joy)
			for button = 1, j.numButtons do
				j.buttons[button] = false
			end
		end
		for axis = 1, j.numAxes do
			j.axes[axis] = love.joystick.getAxis(joy, axis)
		end
		for button = 1, j.numButtons do
			j.buttons[button] = love.joystick.isDown(joy, button)
		end
	end
end

function love.draw()
	local y = 0
	local height = love.graphics.getFont():getHeight()
	for _, joy in ipairs(state) do
		y = y + height
		love.graphics.print(joy.name .. ":", 10, y)
		for axis, value in ipairs(joy.axes) do
			y = y + height
			love.graphics.print("A" .. axis .. ": " .. value, 20, y)
		end
		for button, value in ipairs(joy.buttons) do
			y = y + height
			love.graphics.print("B" .. button .. ": " .. tostring(value), 20, y)
		end
	end
end
I have no idea what I'm doing
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PS3 Controller joysticks sticks

Post by bartbes »

You should be more specific, what is it you want explained?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests