I have this code for a pong game I am making:
local function removeBall() if (ball.x \< 0) or (ball.x \> 1200) then display.remove(ball) print("removed") end end Runtime:addEventListener("enterFrame", removeBall)
But I keep getting this error:
ERROR: Runtime error main.lua:28: attempt to compare nil with number stack traceback: main.lua:28: in function '?' ?: in function \<?:172\>
And it points to this line:
if (ball.x \< 0) or (ball.x \> 1200) then
This is how I made the ball:
local ball = display.newCircle(display.contentCenterX, display.contentCenterY, 20) physics.addBody(ball, "dynamic", {isSensor = true}) ball:setLinearVelocity(math.random(-400, 400), math.random(-200, 200))
Any help would be appreciated.