My game uses balls and each time a ball makes it to the target I remove it from the game board, make the object in active and I am removing and recycling the object. I had to remove it so that the object did not interfere with other balls going into the same target. Everything during game play works fine.
The problem arises after I finish the game I transition to an End Game Screen and then to a screen I track the levels available for game play. When I press the level number I want to replay I get the following error message:
attempt to index global ‘ball1’ (a nil value). I goes on to reference line 1030.
Below is my code:
if event.other.id == “gameBall1” then
scoreTotal = scoreTotal + ball1.value
totalBalls = totalBalls + ball1.count
ball1.active = false
ball1.isvisible = false
ball1:removeSelf(shouldRecycle)
ball1 = nil
print (“Removed Game Ball 1”)
1030: ball1:addEventListener(“collision”, ball1)
Question: Am I removing the ball once it hits the target incorrectly? If so, what should I do differently?
Thanks