Hi,
I having problems solving an issue where i try to reset a ball (the player if you will) in my level after loosing a life.
In the collision event that determines the loss condition (losing a life) i use the follwing code to remove the ball:
[lua]ball:removeSelf();
ball = nil;
resetBall(group);[/lua]
then call a resetBall() function to recreate it in the right location:
[lua]function resetBall(group)
local ball = display.newImage( group, “IMG/ball.png”, 150, -0 )
ball.id = “Ball Object”;
ball.myName = “ball”;
physics.addBody( ball, { density=1.0, friction=0.0, bounce=1, radius=25 } )
ball:applyForce( 500, 100, ball.x, ball.y )
end[/lua]
And i get the error:
attempt to index local ‘ball’ (a nil value) or
attempt to index global ‘ball’ (a nil value) (if i remove local).
I have also tried to add a: local ball on top, but that gives me the error:
attemt to index upvalue ‘ball’ (a nil value)
Any idea on how to get around this, or a better approach of solving the problem would be very appreciated.
Thanks