Not sure I understand. Map is a "y" table (first subindex). Each element of the "y" table contains an "x" table.
If you put the 0 or 1 or 2 or 3 into the "y" table, you will be overwriting one "x" table.
Where do you want the 0 or 1 or 2 or 3 exactly? The most logical place seems to be inside the "x" tables, because if you place it in the "y" table, you're replacing one of the "x" tables with a number (which is the problem you were having). Also, the other function seems to expect the values to be indeed in the "x" tables.
And I don't get how you want them distributed. Do you want each cell different? Do you want to fill the terrain with all the same value, just that value is random from 1 to 4? Do you want them scattered, like rocks or coins?
I'll show you both just in case. You seem to have defined three types: grass (1), dirt (2) and stone (3). Let's imagine that you want each cell to randomly be either grass or dirt, and then have some stones scattered.
To do this, first you iterate over all tables, changing values in them, then you scatter some rocks (probably a percentage of the total number of cells):
Code: Select all
-- first, fill each cell at random with either grass or dirt
for y, xs in ipairs (map) do
for x, value in ipairs (xs) do
xs[x] = love.math.random(1, 2) -- a value between 1 and 2
-- next, scatter some stones
for i = 1, width * height * (5/100) do -- 5% of stone (approx)
local y = love.math.random(1, height)
local x = love.math.random(1, width)
map[y][x] = 3