Attempt to compare nil with number Error in Lua (Corona Lab) -
i'm new corona (lua). after running game, game seems work perfectly, until few seconds later when following error: 'attempt compare nil number'
local function gameloop()
-- create new asteroids createasteroid() -- remove asteroids have been drifted off screen = #asteroidstable, 1, -1 local thisasteroid = asteroidstable [i] if (thisasteroid.x < -100 or thisasteroid.x > display.contentwidth + 100 or thisasteroid.y < -100 or thisasteroid.y > display.contentheight + 100 ) display.remove( thisasteroid ) table.remove( asteroidstable) end end
end
as can see above, 'thisasteroid' in 'asteroidstable = {}' defined variable in top of module , outside of function.
local asteroidstable = { }
thanks help!
either thisasteroid.x
, thisasteroid.y
, display.contentwidth
or display.contentheight
nil
.
use print(thisasteroid.x)
etc find out 1 nil
.
you should line number with error message helps find problem.
once have found nil
value either have prevent becoming nil
or if can't should restrict comparison non-nil
values.
Comments
Post a Comment