So I am making a car dodging game and I was redoing the spawn system when I encountered this problem. I tried to debug it but had no success. So I looked online and through the forums and found that this issue isn’t very popular. I want to make it so when an obstacle reaches a certain y value it allows another obstacle to spawn. This will allow me to slowly increase the difficulty by making cars spawn more frequently and by making sure the player has enough space to fit through. With this code I get an error saying attempting to compare numbers with nil. Meaning that it did not remove the listener.
Here is the code with the issue
[lua]function Cars:enterFrame()
if self.cars.y > spawnLine then
carsAlive = carsAlive - 1
end
end
function Cars:moveCar()
function destroyCar()
self.cars:removeEventListener(“enterFrame”, self)
self.cars:removeSelf()
end
Runtime:addEventListener(“enterFrame”, self);
transition.to( self.cars, { time=self.velocity, x=self.cars.x, y=550, onComplete=destroyCar} )
end[/lua]
I don’t know if anyone knows what is wrong and can help me fix it or another way I can go about making a good spawning system
Thanks