在 Lua(ipad 上的 Codea)中,我制作了一个程序,其中有四对 XY 坐标,它们放在相同 id 下的表中(计数 = 计数 + 1)当我第一次使用一对来测试代码时,检测 XY 坐标何时触及表中的坐标之一(坐标已经位于该坐标的位置)。我使用这段代码做到了这一点:
if (math.abs(xposplayer - posx) < 10) and (math.abs(yposplayer - posy) < 10) and id < (count - 10) then
这段代码正在这个循环中播放:
for id,posx in pairs(tableposx) do
posy = tableposy[id]
这就像我想要的那样工作!
但现在我有 8 个表(tableposx1 tableposy1,...)我想检查当前坐标是否触及任何表中的任何坐标(曾经)所以我尝试了:
for id,posx1 in pairs(tableposx1) do
posy1 = tableposy1[id]
posy2 = tableposy2[id]
posx2 = tableposx2[id]
posy3 = tableposy3[id]
posx3 = tableposx3[id]
posy4 = tableposy4[id]
posx4 = tableposx4[id]
而这个位四次(对于四个当前坐标)
if ((math.abs(xposplayer1 - posx1) < 10) and (math.abs(yposplayer1 - posy1) < 10))
or ((math.abs(xposplayer1 - posx2) < 10) and (math.abs(yposplayer1 - posy2) < 10))
or ((math.abs(xposplayer1 - posx3) < 10) and (math.abs(yposplayer1 - posy3) < 10))
or ((math.abs(xposplayer1 - posx4) < 10) and (math.abs(yposplayer1 - posy4) < 10))
and (id < (count - 10))
但这总是(几乎)成立。并且因为有时表中的值是 NIL,它会给我一个错误,说它不能将某些东西与 nil 值进行比较。
在此先感谢,劳伦特