Here is how I generate the positions for each cell in the array
local bwidth = 10
local bheight = 20
bheight += 2 --extra empty space just in case
local Grid = {}
for i = 1, bheight do
local WidthArray = {}
for j = 1, bwidth do
local position = anchor.CFrame.Position + Vector3.new(j * 2, i * 2, 0)
local clone = anchor:Clone()
clone:PivotTo(CFrame.new(position))
WidthArray[j] = { ["Position"] = clone.Position }
clone.Parent = workspace.Board2
clone.Transparency = 0
if i >= bheight-1 then
clone.Transparency = .5
end
end
Grid[i] = WidthArray
end
and this is the comparison function
local function collisioncheck(type, increment)
local comparisonresult
local okay = workspace.Active:GetChildren()[1]
okay:Clone().Parent = workspace.Collision
local THETHING = workspace.Collision:GetChildren()[1]
local temptable = {}
local piecesinactive = {}
for i1, v1 in ipairs(Grid) do --Sets up a temporary table for cells that are occupied (not air)
for i2, v2 in v1 do
table.insert(temptable, v2)
end
end
local function iteratethruactive() --grab the position for the current active piece
for i, v in THETHING:GetChildren() do
piecesinactive[i] = v.Position
end
return piecesinactive
end
local function compare() --compares temptable with pieceinact
for i, v in temptable do
if table.find(iteratethruactive(), v.Position) then
print("yes!")
comparisonresult = true
else
warn("no!")
print(iteratethruactive(), v.Position)
end
end
end
...
I did try to print the table.find, and it returns nil instead of something like true or false.
Am I using the wrong function for this case or is there something wrong with my implementation?