Löve crashes when trying to identify key presses
Posted: Sat Jan 18, 2014 8:32 pm
Hello there, I am quite new to Löve and Lua, I've only worked with Arduino before. I'm trying to make Löve register the keys W, A, S and D, however Löve crashes when either key is pressed. This is the code:
Thanks
Code: Select all
-- Controls Pressed
function love.keypressed(key)
while key == 'w' do
w_down = true
end
while key == 'a' do
a_down = true
end
while key == 's' do
s_down = true
end
while key == 'd' do
d_down = true
end
end
-- Controls Released
function love.keyreleased(key)
if key == 'w' then
w_down = false
end
if key == 'a' then
a_down = false
end
if key == 's' then
s_down = false
end
if key == 'd' then
d_down = false
end
end
-- Draw
function love.draw()
while w_down == true do
love.graphics.print('W is pressed', 400, 300)
end
while a_down == true do
love.graphics.print('A is pressed', 400, 300)
end
while s_down == true do
love.graphics.print('S is pressed', 400, 300)
end
while d_down == true do
love.graphics.print('D is pressed', 400, 300)
end
end