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

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.
Post Reply
ziodice
Prole
Posts: 15
Joined: Thu Feb 23, 2012 8:35 pm

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

Post 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.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

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

Post by MadByte »

"spacebar" is not the right constant. It's " " (basically just the actual character)
Keyconstants
ziodice
Prole
Posts: 15
Joined: Thu Feb 23, 2012 8:35 pm

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

Post 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?
User avatar
slime
Solid Snayke
Posts: 3181
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post 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.)
User avatar
Jasoco
Inner party member
Posts: 3728
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

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

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], hyreia and 6 guests