【发布时间】:2017-03-19 17:38:17
【问题描述】:
我对 Corona (Lua) 完全陌生。运行游戏后,游戏似乎运行良好,直到几秒钟后我收到以下错误:'Attempt to compare nil with number'
本地函数gameLoop()
-- create new asteroids
createAsteroid()
-- remove asteroids which have been drifted off the screen
for i = #asteroidsTable, 1, -1 do
local thisAsteroid = asteroidsTable [i]
if (thisAsteroid.x < -100 or
thisAsteroid.x > display.contentWidth + 100 or
thisAsteroid.y < -100 or
thisAsteroid.y > display.contentHeight + 100 )
then
display.remove( thisAsteroid )
table.remove( asteroidsTable)
end
end
结束
正如您在上面看到的,“thisAsteroid”位于“asteroidsTable = {}”中,它被定义为模块顶部和任何函数外部的变量。
本地小行星表 = { }
感谢您的帮助!
【问题讨论】:
-
尝试在遇到错误的行之前使用
print语句。 -
您能否更具体一些并举例说明打印语句? (对不起,我是编码新手)