I'm not sure if I have a syntax error or a lack of understanding here, but I've been puzzled about a bug that I haven't been able to fix for half an hour.
link = {}
link.y = 1
link.speed = 1
link.x = 1
function love.load()
link = love.graphics.newImage("sprites/link solo.png")
end
function love.update(dt)
if love.keyboard.isDown('w') then
link.y = link.y - link.speed; [LINE WHERE ERROR OCCURS]
end
end
function love.draw()
love.graphics.draw(link, link.x, link.y)
end
The problem is with your love.load. You're effectively replacing the link table with an image, and as such the values you assigned at the top of your code do not exist anymore, causing the error.
function love.load()
link.image = love.graphics.newImage("sprites/link solo.png") -- store the image under 'image' key in the table
end
function love.draw()
love.graphics.draw(link.image, link.x, link.y) -- note the added .image
end