Table = {} -- table
Table.First = 1 -- new index
Table["Second"] = {} -- alternative version
table.insert(Table, Item) -- adds Item
table.remove(Table, Item) -- removes item
But its not really what im asking, I’m more asking the question of checking the Descendants of a Table, We can use a for loop to iterate through the Children, but not what’s in the children. The Descendants.
Obviously I can have a system to iterate through the table and type check if the index value is a table, or by the usage of table.find(), but i feel like that would just cause performance issues becauase what if there is multiple?
I was wondering if it was Possible to do this while being efficient and good for Performance?
If I understand correctly, you could use multiple for loops to iterate through both.
for i, v in pairs(t) do
--// Any other code here
for y, x in pairs(v) do
--// Any other code here
for w, z in pairs(x) do
--// Any code here
end
end
end
I’m not entirely sure using table.find() a bunch is the greatest idea for performance, but it would be least intensive (writing wise); however, the multiple for loops would probably be better on performance I think.
local function FindTableDescendant(Dictionary, IndexName)
local found
for key, val in pairs(Dictionary) do
if typeof(val) == "table" then
if key == IndexName then
found = val
break
else
found = FindTableDescendant(val, IndexName)
end
end
end
return found
end
However yeah, basically what ive done. It could just be me overreacting over some parts, but i was asking for a more faster way than this, if there isnt, I’ll just mark this as solution.
This in the worst case will go through every item in the table. With no method to skip some items knowing that the thing won’t be in there, this is the fastest you can make it.
you can probably do a repeat loop and use type()/typeof() (honestly I don’t know the difference) to check if what you got is a table and then just keep doing it until there isn’t anymore tables descending