Page 1 of 1

Various button pressing functions don't seem to do anything?

Posted: Mon Aug 11, 2014 8:32 pm
by ziodice
So, I've just been messing around with it, not necessarily trying to make a game or anything, but I've been trying to have the program show a picture when I press spacebar.

Code: Select all

function love.load()
	love.graphics.setBackgroundColor(255,0,0)
	<what I named the picture> = love.graphics.newImage("<the name of the picture>")
end

function love.draw()
	if love.keyboard.isDown("spacebar") then
		love.graphics.draw(<what I named the picture>, 300, 400)
	end
end
I have also tried doing this with a

Code: Select all

love.keypressed(key)
function, but that wasn't working either. What happens, in effect, is I run it, it displays backgrounds, no errors, but nothing seems to happen when I press spacebar.

Re: Various button pressing functions don't seem to do anyth

Posted: Mon Aug 11, 2014 8:34 pm
by MadByte
"spacebar" is not the right constant. It's " " (basically just the actual character)
Keyconstants

Re: Various button pressing functions don't seem to do anyth

Posted: Mon Aug 11, 2014 8:36 pm
by ziodice
Wow, I feel stupid now. See, I assumed it was an issue with the code because "esc" didn't work either, is "esc" also not the right code for the escape key?

Re: Various button pressing functions don't seem to do anyth

Posted: Mon Aug 11, 2014 8:47 pm
by slime
ziodice wrote:is "esc" also not the right code for the escape key?
It's "escape" (as listed on the page MadByte linked.)

Re: Various button pressing functions don't seem to do anyth

Posted: Tue Aug 12, 2014 3:09 am
by Jasoco
This got me too back when they switched to using string constants for keys. I was doing "space" too.

Others to remember, Escape is "escape", Enter is "return". You also have Control, Alt, Option, Command and Windows which are "rctrl" or "lctrl" for Right and Left Control, "ralt" and "lalt" for Right and Left Alt (or Option on OS X) and "rgui" and "lgui" for Right and Left Windows Key (Command on OS X).