local module = {}
function module.GenerateNoiseMap(mapWidth, mapHeight, scale)
local noiseMap = {mapWidth, mapHeight}
if scale <= 0 then
scale = 0.0001
end
for y = 0,mapHeight do
for x = 0,mapWidth do
local sampleX = x/scale
local sampleY = y/scale
local perlinValue = math.noise(sampleX, sampleY)
noiseMap[x][y] = perlinValue
end
end
return noiseMap
end
return module
From your error, (I believe that) it is caused by setting something to nil, while thinking it is a number. I don’t do math much, but try changing the 0s in the for loops to 1s. I’m going off for a while, I won’t reply
Just try changing 0 to 1, in your code I see division, and since it starts from 0, it turns to 0/scale, which is 0. And ultimately that would be very broken
local module = {}
function module.GenerateNoiseMap(width, height, scale)
local noise = {}
if scale <= 0 then
scale = 0.0001
end
for y = 1, height do
for x = 1, width do
local perlin = math.noise(x/scale, y/scale, 0)
noise[x] = perlin
noise[y] = perlin
end
end
return noise
end
return module