【发布时间】:2011-05-31 22:52:38
【问题描述】:
下面的update() 函数在游戏的每一帧都被调用。如果Drop 粒子的 y 值大于 160,我想将其从表中删除。问题是我收到“尝试将数字与 nil 进行比较”错误,如下所示:
local particles = {};
function update()
local num = math.random(1,10);
if(num < 4) then
local drop = Drop.new()
table.insert ( particles, drop );
end
for i,val in ipairs(particles) do
if(val.y > 160) then --ERROR attempt to compare number with nil
val:removeSelf(); --removeSelf() is Corona function that removes the display object from the screen
val = nil;
end
end
end
我做错了什么?显然val 是 nil,但我不明白为什么表迭代会首先找到 val,因为当它的 y 值大于 160 时我将它设置为 nil。
【问题讨论】:
标签: lua coronasdk lua-table particles