Page 1 of 1

keyboard.isDown multi key check not working?

Posted: Fri Sep 16, 2011 2:12 am
by bunktacular
I'm new to the LOVE engine and only lightly experienced in LUA, but I have a small little problem I would like to get the some help with, preferebly with reasoning so I can learn and improve.

Basically, I want to check if none of the game's control keys are held down.

Code: Select all

--slow down if no keys down
anyDown = love.keyboard.isDown( right, left, up, down )
if anyDown == false then
	yspeed = 0
end
According to this page, this command should return true or false, but it returns nil and causes
the game to crash before starting.

My error states that on that line: bad argument #1 to 'isDown' (string expected, got nil)
This all takes place within love.update.

Is there something little I am missing?
Is that function broken/bugged?
Am I being stupid with a much better method in doing this?

Re: keyboard.isDown multi key check not working?

Posted: Fri Sep 16, 2011 3:25 am
by TechnoCat

Code: Select all

anyDown = love.keyboard.isDown( 'right', 'left', 'up', 'down' )
And anyDown will be true if any of those keys are pressed at any time.

Re: keyboard.isDown multi key check not working?

Posted: Fri Sep 16, 2011 4:35 am
by bunktacular
Alright, that fixed it.

Thank you very much, +1.


yspeed = 0 was just a placeholder so that I would know if it was working, the actual function will be much different.

Re: keyboard.isDown multi key check not working?

Posted: Fri Sep 16, 2011 7:29 am
by Robin
Note that any time LÖVE wants one of several named values (called Enums on the wiki), it means that those values are strings.