You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Rather than simply creating one part for each space in my 2D grid of land, I was trying to implement a part generator for the grid which would combine the possible grid spaces and generate a single part for all of the spaces, which was a partial success. This is what I have achieved so far:
The brown parts are the parts the code is supposed to skip, and generate parts around them.
- What is the issue? Include screenshots / videos if possible!
I implemented it in 1D, how can I go about implementing it in 2D like so:
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried using the floodfill algorithm, breadth-first search, and this algorithm I found. Maybe they are the solutions but my implementation went horribly wrong.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
My code that generates the parts in 1D:
function plot:draw()
local function fill(sp, ep, s)
local p = script[s]:Clone();
p.Position = (sp + ep) / 2;
p.Size = Vector3.new(math.abs(sp.X - ep.X), 0, math.abs(sp.Z - ep.Z)) + script[s].Size;
if s == "Default" then
p.BrickColor = BrickColor.random();
end
p.Parent = workspace;
return p;
end
for i, row in ipairs(self.land) do
local lastPos = nil;
local lastValidPos = nil;
local lastState = nil;
for j, l in ipairs(row) do
local s = l:getState();
if j == 1 then
lastPos = l.position;
lastValidPos = l.position;
lastState = s;
continue;
end
if s ~= lastState then
fill(lastPos, lastValidPos, lastState);
lastPos = l.position;
end
lastState = s;
lastValidPos = l.position;
end
fill(lastPos, lastValidPos, lastState);
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.