Reading Error Messages
Posted: Fri May 27, 2016 10:31 pm
So I tried to open up my game in Love but I keep getting this message:
Error
main.lua:43: attempt to compare nil with number
Traceback
main.lua:43: in function 'update'
[C]: in function 'xpcall'
Here is my code:
So what did I do wrong, and how do I read those messages so i don't need help anymore?
Error
main.lua:43: attempt to compare nil with number
Traceback
main.lua:43: in function 'update'
[C]: in function 'xpcall'
Here is my code:
Code: Select all
local player
local p_x
local p_y
local p_speed
local stillhere
function love.draw()
love.graphics.setBackgroundColor(0,0,0)
end
function love.load()
player = love.graphics.newImage('human1.png')
p_x = 0
p_y = 0
p_speed = 100
end
function love.update(dt)
--Left/Right
if love.keyboard.isDown("a") then
p_x = p_x - p_speed * dt
player = love.graphics.newImage('human3.png')
end
if love.keyboard.isDown("d") then
p_x = p_x + p_speed * dt
player = love.graphics.newImage('human1.png')
end
--Up/Down
if love.keyboard.isDown("s") then
p_y = p_y + p_speed * dt
player = love.graphics.newImage('human4.png')
end
if love.keyboard.isDown("w") then
p_y = p_y - p_speed * dt
player = love.graphics.newImage('human2.png')
end
-- Left/Right Collision
if p_x <0 then
p_x = 0
end
if p_x > love.graphics.getWidth() - player:getWidth() then
p_x = love.graphics.getWidth() - player:getWidth()
end
--Up/Down Collision
if p_y < 0 then
p_y = 0
end
if p_y > love.graphics.getHeight() - player:getHeight() then
p_y = love.graphics.getHeight() - player:getHeight()
end
end
function love.draw()
love.graphics.draw(player, p_x, p_y)
end
love.timer.sleep(5)
function love.load()
stillhere = love.graphics.newImage("waysh.png")
stillhere_x = 100
stillhere_y = 100
end