20

How can I make a 2D array with Lua? I need to dynamically create this.

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].

Thanks

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
user441521
  • 6,942
  • 23
  • 88
  • 160

1 Answers1

36
-- 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
TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58