I have a problem . When the ball falls from the screen , and the user clicks it , it’s suppose to disappear . But it doesn’t . I get an error that says :
game.lua:50: attempt to index local 'event' (a nil value)
This is the code :
function Ball:touch( self, event ) if ( event.phase == "ended" ) then --line 50 print( "Touch event began . " ) end end
local numberBall = 3 --local variable; amount can be changed local function clearBall( thisBall ) display.remove( Ball ) Ball = nil end local function spawnBall() for i=1, numberBall do Ball = display.newCircle(60, 60, 13) -- when you create it with 'local', it won't be the same Ball object but a new one Ball:setFillColor( 0, 5, 0 ) physics.addBody(Ball, "dynamic", {density=0.1, bounce=0.1, friction=0.1, radius=0}) Ball:applyLinearImpulse(-.05, .05, 0, 0) -- you first need to add a physics body before you apply linear impulse Ball.id = "Ball" Ball.x = math.random(10, 300); Ball.y = 50; 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 } ); -- redundant because you have already added a physics body to Ball end end
Also when I click on other balls they don’t do anything I have to click a specific ball to get a reaction . How do I change this ?