Using Lua tables as 2-dimensional arrays
snippet in lua

Using Lua tables as 2-dimensional arrays

user2394

local MapTable = {}
local Maximum_X, Maximum_Y = 32, 16
local Start_X, Start_Y = 64, 32

function love.load()
    for y = 1,Maximum_Y do
        local row = {}
        for x = 1,Maximum_X do
            table.insert(row,2)
        end
        table.insert(MapTable,row)
    end
end

function love.draw()
    for y,row in ipairs(MapTable) do
        for x,idx in ipairs(row) do
            love.graphics.draw(Tileset[idx], Start_X + 32*(x-1), Start_Y + 32*(y-1))
        end
    end
end