我已经编写了以下函数,在屏幕上绘制网格(使用X-Plane 10中的FlyWithLua)。
它工作并绘制网格,框/标签和所有东西,显然它创建了"lt_box"三维数组,因为当我在循环中打印(注释掉的打印指令)时,它打印正确的值。
问题是,如果我从代码的任何其他部分调用lt_box[x][y][z],我无法获得这些值…
任何想法?
function draw_lt_table()
idx = 1
idx2 = 1
xx1 = rth_box[1]
xx2 = rth_box[2]
yy1 = rth_box[3]
yy2 = rth_box[4]
lite_idx = 1
cell_x_size = 38
cell_y_size = 40
num_cols = 6
num_rows = 6
lt_box = {}
if d_tab==false or d_stg==false then
return lt_box
end
for idx2 = 1,num_rows,1 do
for idx = 1,num_cols,1 do
lt_box[idx] = {}
lt_box[idx][idx2] = {xx1+((cell_x_size*idx)-cell_x_size), xx1+(cell_x_size)*idx, 1+yy2+((cell_y_size*idx2)-cell_y_size), 1+yy2+(cell_y_size)*idx2}
graphics.set_color(0, 0, 0, 0.7)
graphics.draw_rectangle(lt_box[idx][idx2][1], lt_box[idx][idx2][3], lt_box[idx][idx2][2], lt_box[idx][idx2][4])
graphics.set_color(1, 1, 1, 0.7)
graphics.set_width(2)
graphics.draw_line(lt_box[idx][idx2][1],lt_box[idx][idx2][3],lt_box[idx][idx2][1],lt_box[idx][idx2][4])
graphics.draw_line(lt_box[idx][idx2][1],lt_box[idx][idx2][4],lt_box[idx][idx2][2],lt_box[idx][idx2][4])
graphics.draw_line(lt_box[idx][idx2][2],lt_box[idx][idx2][4],lt_box[idx][idx2][2],lt_box[idx][idx2][3])
graphics.draw_line(lt_box[idx][idx2][2],lt_box[idx][idx2][3],lt_box[idx][idx2][1],lt_box[idx][idx2][3])
light_up(unpack(lt_box[idx][idx2]))
glColor4f(1, 1, 1, 0.7)
draw_string(lt_box[idx][idx2][1]+12, lt_box[idx][idx2][3]+30, lite_idx)
draw_string(lt_box[idx][idx2][1]+3, lt_box[idx][idx2][3]+15, lites_vars[4][lite_idx])
draw_string(lt_box[idx][idx2][1]+3, lt_box[idx][idx2][3]+5, lites_vars[lt_set][lite_idx])
lite_idx = lite_idx+1 -- this is usd in line 115-116 to select values as labels
--[[
print("LT_BOX " .. idx .. " " .. idx2 .. " x1 ".. lt_box[idx][idx2][1])
print("LT_BOX " .. idx .. " " .. idx2 .. " x2 ".. lt_box[idx][idx2][2])
print("LT_BOX " .. idx .. " " .. idx2 .. " y1 ".. lt_box[idx][idx2][3])
print("LT_BOX " .. idx .. " " .. idx2 .. " y2 ".. lt_box[idx][idx2][4])
print("****************************************************************************")
--]]
end
--print("____________________________________________________________________________")
end
end
内部循环中有lt_box[idx] = {}
,这意味着每次添加元素时都要重置该表。你必须在外循环中创建这个表。
for idx = 1,num_cols,1 do
lt_box[idx] = {}
for idx2 = 1,num_rows,1 do