Trying to reference specific value from {} object throws 'nil value' error
Posted: Wed Apr 24, 2019 1:49 pm
Hi all,
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.
Here are the relevant code bits:
Throws the following error:
Where am I going wrong?
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.
Here are the relevant code bits:
Code: Select all
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
Code: Select all
main.lua:21: attempt to perform arithmetic [b]on field 'y' (a nil value)[/b]
Traceback
main.lua:N: in function 'update'
[C]: in function 'xpcall'