I am trying to make all the balls disappear when I touch on them but I am getting this error when I touch them :
77: attempt to index global 'Ball'
This is all the relevant code :
local numberBall = 3 local function spawnBall() for i = 1 , numberBall do local Ball = display.newCircle(60, 60, 13) Ball.x = math.random(10, 300); Ball.y = 50; Ball:setFillColor( 0, 5, 0 ) transition.to( Ball, { time=math.random(4000,8000), x=math.random(-10,100) , y=600, onComplete=clearBall } ); physics.addBody( Ball, "dynamic", { density=0.1, bounce=0.1, friction=0.1, radius=0 } ); end end spawnBall()
local function handleTouch(event) if ( event.phase == "ended" ) then display.remove(Ball) end end
function scene:show(event) Ball:addEventListener("touch", handleTouch) end function scene:hide(event) Ball:removeEventListener("touch", handleTouch) --where the error is composer.removeScene( "restart" ) end