So I am basically creating a tactical RPG game like Advance Wars and Fire Emblem and I’ve created an algorithm that creates a random board using an multidimensional table. What I want to do is to print every member of the WorldList table and delete a random part inside the array and replace it with a different part.
The problem that I’m getting is that the print method is printing the index of the members of the table and my code doesn’t destroy the random part in the table.
If I can get any help, that would be much appreciated.
Here’s the code I have so far:
WorldList = {}
for x = 0,20 do
WorldList[x] = {}
for y = 0,20 do
local partIndex = math.random(1,#Parts:GetChildren())
local newPart = Parts:GetChildren()[partIndex]:Clone()
newPart.Name = "Tile" .. x .. "," .. y
newPart.Parent = workspace.World
newPart.CFrame = CFrame.new(x*4-25 , 3 , y*4-25)
newPart.Anchored = true
WorldList[x][y] = {newPart.Name}
end
end
--Prints the index instead
for index, value in ipairs(WorldList) do
print(index, value)
end
--Delete a random part inside WorldList and replace it with the Base Castle
local homeX = math.random(1,#WorldList)
local homeY = math.random(1,#WorldList)
print(WorldList[homeX][homeY])
WorldList[homeX][homeY]:Destroy()
--Makes a castle
local myBase = HomePart:Clone()
myBase.Parent = workspace.World
myBase.CFrame = CFrame.new(homeX *4- 25 , 3 , homeY* 4- 25)
myBase.Anchored = true
WorldList[homeX][homeY] = {myBase}