Page 1 of 1

trouble with keyreleased( key )

Posted: Wed Feb 25, 2009 4:02 am
by Zae
Hi every one, i'm new to programming at all, and to LOVE in particular. i've got code

Code: Select all

function keypressed(...)

	if key ~= love.key_space and fire == 0 then
		love.audio.play( pew )
		fire = 0.01
		table.insert(bullets, {x = x, y = y-15})
	end
the function work when any key pressed, i need it to work when "space" key pressed, what must i do?
Thanks.

Re: trouble with keyreleased( key )

Posted: Wed Feb 25, 2009 4:27 am
by Kaze
function keypressed(...)
should be:
function keypressed( key )

Re: trouble with keyreleased( key )

Posted: Wed Feb 25, 2009 5:24 am
by zapwow
You have:

Code: Select all

if key ~= love.key_space and fire == 0 then
Let's take a closer look:
  • if key ~= love.key_space

closer...
  • ~=

This means "is not equal". You want "is equal", like you have "fire == 0"

Code: Select all

if key == love.key_space and fire == 0 then

Re: trouble with keyreleased( key )

Posted: Wed Feb 25, 2009 3:30 pm
by Zae
Thanks very much guys, it works.