I'm about to finish my game, but I ran into an error:
attempt to compare nil with number game2.lua 444
I don't have a clue on how to fix this, and I've tried quite everything, with no success. I think the function scrollSpace
is causing this, because sometimes the background would scroll at an uncontrollable speed. Here is my code:
function scrollSpace(self,event)
if self.x < -900 then
self.x = 800
else
self.x = self.x - self.speed
end
end
This controls how the stuff scroll across the screen. If you guys what more code, just reply, and I'll be happy to add the requested source. One last thing: does anyone know what the following error means:
attempt to compare nil with number
this is my file code:
coin01 = display.newImage("coin02.png")
coin01.y = 100
coin01.x = 500
coin01.speed = math.random(2,6)
coin01.initY = mine1.y
coin01.amp = math.random(20,100)
coin01.angle = math.random(1,360)
physics.addBody(coin01, "static", {density=.1,bounce=0.1, friction=.2,radius=12})
screenGroup:insert(coin01)
end -- end of create scene
**print "passed"
function scrollSpace(self,event)
if self.x < -900 then
self.x = 800
else
self.x = self.x - self.speed
end
end**
function scene:enterScene(event)
coin01.enterFrame = coins
Runtime:addEventListener ("enterFrame",coin01)
end
function scene:exitScene(event)
***storyboard . purgeScene ("start")
story board . purgeScene ("restart")***
Runtime:removeEventListener ("enterFrame",coin01)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene",scene)
scene:addEventListener("enterScene",scene)
scene:addEventListener("exitScene",scene)
scene:addEventListener("destroyScene",scene)
return scene