Error main.lua:29: attempt to index global 'mole' (a nil value) Traceback [love "callbacks.lua"]:228: in function 'h
Posted: Thu Mar 09, 2023 8:59 pm
Hello there, I was following Challacade's tutorial and tried editing the target with an image. I have the cursor completed yet there is an error message:
Please tell me if anything is wrong as I am quite new to Love.
Code: Select all
function love.load()
love.mouse.setVisible(false)
mouseImg = love.graphics.newImage("mouse.png")
moleImg = love.graphics.newImage("mole.png")
gameFont = love.graphics.newFont("karma future.ttf", 45)
score = 0
end
function love.update(dt)
end
function love.draw()
love.graphics.setFont(gameFont)
mole = love.graphics.draw(moleImg, 100 ,500)
x, y = love.mouse.getPosition()
love.graphics.draw(mouseImg, x, y)
love.graphics.print("Score: "..score)
end
function love.mousepressed(x, y, button, istouch)
size = mole.getWidth() * mole.getHeight()
distance = distanceBetween(x, y, mole.getX(), mole.getY())
if button == 1 then
if distance < a then
score = score + 1
end
end
end
function distanceBetween(x1, x2, y1, y2)
return math.sqrt((y2 - y1)^2 + (x2 - x1)^2)
end