#how to check what an item in a table is

1 messages · Page 1 of 1 (latest)

split elk
#

so basically im tryna make a function that will merge any 2 tables into 1, and i wanted to allow the second table to contain tables that can be broken down into their individual objects, but the problem is that i'm having issues detecting if an item in the table is a table, i tried the :IsA() function, but that produces an error since I'm testing with a table of strings and not a table of tables. Any tips?

heres the code

local module = {}

function mergeTables(table1:SharedTable,table2:SharedTable,BreakTable2:boolean) -- BreakTable2 determines if table2 is broken into objects
    for i = 1, #table1 do
        if table2[i]:IsA("SharedTable") and BreakTable2 == true then
            mergeTables(table1,table2[i])
        else
            table.insert(table1,table2[i])
        end
    end
    
    return table1
end

function module.merge(baseTable:SharedTable, addTable:SharedTable, BreakTable:boolean)
    local result = baseTable
    
    result = mergeTables(result,addTable,BreakTable)
    
    return result
end

return module
runic bison
#

Also use pairs() instead of numeric indexing so it works with any table structure not just arrays

spark moat
split elk
#

holup

#

when testing with tables in tables it just adds the table to the base table

cosmic oyster
round egret
split elk
#

actually give me a sec

#

yeah i did

#

its not detecting that the item is a table

#

this is the if statement line ```lua
if typeof(table2[i]) == SharedTable and BreakTable2 == true then

#

fixed it

#

nvm

#

everything works now

#

just changed the sharedtable to a string, "table"

split elk
#

update: it decided to stop working

round egret
#

👀

#

any errors this time

split elk