I am trying to make a program that will build something (a circle or sphere for now) by:
1. defining the coordinates at which to place a block and storing these in a table.
2. calling on those tables to place blocks.
I want to generate the names of tables automatically because I don't know ahead of time how many I will need (Also, it seems like a cool thing to do). I think it then makes sense to generate the names again when I want to access a particular table.
However, I don't know what I doing and it isn't working (I bet you are surprised). I know that the way I am defining and calling on my tables is wrong, but I don't know how to fix it. Please help. Also if you have a better idea on how to store and recall coordinates in a table, that would be greatly appreciated.
function domeQuadrantTables(rad)
--make a table for each layer of quarter dome with x, y coordinates. x, y, and z are positive.
for j = 0, rad do
if j < round(math.sqrt((rad^2)/3)) then
for i = 0, round(math.sqrt(rad^2/2)) do
z = j
y = i
x = round(math.sqrt(rad^2 - y^2 - z^2))
if y >= x then
limit = y
for i = limit, 0, -1 do
z = j
x = i
y = round(math.sqrt(rad^2 - x^2 - z^2))
xy = x .. "," .. y
tablename = "ztable" .. z
tablename = {}
table.insert(tablename, xy)
end
break
end
xy = x .. "," .. y
tablename = "ztable" .. z
tablename = {}
table.insert(tablename, xy)
end
else
for x = round(math.sqrt((2 * rad^2)/3)), 0, -1 do
for y = 0, round(math.sqrt((2 * rad^2)/3)) do
z = round(math.sqrt(rad^2 - x^2 - y^2))
if z == j then
xy = x .. "," .. y
tablename = "ztable" .. z
tablename = {}
table.insert(tablename, xy)
end
end
end
end
end
end
function buildFromTable(rad)
--Reads ztables and builds a quarter dome according to coordinates, layer by layer, bottom up.
--To make a shpere there would be 1 loop for each quarter of a dome, 8 loops total.
--The sign of the x, y, z coordinates and the order of reading from ztables would be changed accordingly in each loop.
for j = 0, rad do
tablename = "ztable" .. j
print(tablename)
for i = 1, table.maxn(tablename) do
xy = tablename[i]
local xytable = {}
for part in string.gmatch(xy, "[^,]+") do
table.insert(xytable, part)
end
x = tonumber(xytable[1])
y = tonumber(xytable[2])
z = j
navigateToZ(x, y, z)
placeBlock()
table.remove(xytable[1])
table.remove(xytable[2])
end
end
end