Hi
In my code I have an if statement that is meant to check if chunkInfo (table) is inside of chunksToRender (table).
I set up a 3 prints, first one shows chunksToRender table, second one shows chunkInfo table and third one shows the output of table.find()
in lua tables are handled by reference and when you compare two tables, you actually compare their references (not their contents). So a table can only be equal to itself.
In this case you are creating two tables (with the “{}” operator) and they will never be equal because they have different references.
local tableA = {{"a","b"}, {"c", "d"}}
local tableB = tableA
print(tableA == tableB)
In this case you only create one table that will be equal to itself.
You can use a table comparison algorithm like this:
function CompareArray(t1,t2)
if #t1~=#t2 then return false end
for i=1,#t1 do
if t1[i]~=t2[i] then return false end
end
return true
end
and use it in a loop to find the position of your chunkInfo table.