I am trying to write a noise-based terrain generator on Roblox. In my current tests, I am only trying to change the occupancies of voxels at the surface. I used a for loop like so to randomize these occupancies:
local chunks = create(FOURTH_CHUNK_SIZE, create(FOURTH_TERRAIN_HEIGHT, create(FOURTH_CHUNK_SIZE, 0.05)))
for i = 1, FOURTH_CHUNK_SIZE * FOURTH_CHUNK_SIZE do
chunks[math.ceil(i / FOURTH_CHUNK_SIZE)][FOURTH_TERRAIN_HEIGHT][i % FOURTH_CHUNK_SIZE + 1] = math.random()
end
(Note: I did originally use two loops, but I found that their behavior can be quite strange. They had the same problem as this snippet.)
However, when I went to test the code, instead of the expected bumpy terrain, I got striations like this:
Note: I have been able to replicate the behavior I wanted by using smaller chunks with these random striations. It isn’t perfect, but it is the best I could do.
Eiminates the use of the single loop and maintains indexing. Avoids having to deal with the i % FOURTH_CHUNK_SIZE
local chunks = create(FOURTH_CHUNK_SIZE, create(FOURTH_TERRAIN_HEIGHT, create(FOURTH_CHUNK_SIZE, 0.05)))
for z = 1, FOURTH_CHUNK_SIZE do
for x = 1, FOURTH_CHUNK_SIZE do
chunks[z][FOURTH_TERRAIN_HEIGHT][x] = math.random()
end
end
Or once again I’m totally wrong. Been working with this stuff for a while.
But without testing … you can never really tell.
Thanks for answering, and sorry I didn’t notice for 11 MONTHS. (Wow I am bad at following up.)
The actual issue ended up being the repeated use of the create function. Apparently, passing a table into create will create multiple references to the same table instead of multiple unrelated tables.