How can I make a 2D array with Lua? I need to dynamically create this.
如何用Lua制作2D阵列?我需要动态创建它。
local tbl = { { } }
Something like the above but where I can specify how many items. In my case they'll be the same amount. I basically want to access it like tbl[3][5].
像上面的东西,但我可以指定多少项。在我的情况下,他们将是相同的金额。我基本上想要像tbl [3] [5]那样访问它。
Thanks
谢谢
1 个解决方案
#1
23
-- Create a 3 x 5 array
grid = {}
for i = 1, 3 do
grid[i] = {}
for j = 1, 5 do
grid[i][j] = 0 -- Fill the values here
end
end
#1
23
-- Create a 3 x 5 array
grid = {}
for i = 1, 3 do
grid[i] = {}
for j = 1, 5 do
grid[i][j] = 0 -- Fill the values here
end
end