Lua (iPad の Codea) で、XY 座標の 4 つのペアがあるプログラムを作成しました。これらは、同じ ID (カウント = カウント + 1) の下のテーブルに配置されます。最初に 1 つのペアのみを使用してコードをテストしたとき、 XY 座標がテーブル内の座標の 1 つ (座標が既に存在する場所) に接触したことを検出します。私はこのビットのコードを使用してこれを行いました:
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]
そして、このビットを 4 回 (4 つの現在の座標に対して)
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 値と比較できないというエラーがスローされます。
前もって感謝します、ローラン