• Removing entries from a table using another table?
    3 replies, posted
Can anyone give me a tip on how do do this? Here's an example: [code] Table1 = { Prop1 , Prop2 , Prop3 , Prop4} Table2 = {Prop1 , Prop2 , Prop4} [/code] How would I use Table2 to remove entries from Table1? Is that even possible?
Here's how I'd do it: [lua]function GetKeyFromValue(t,v) for k,value in pairs(t) do if value == v then return k end end return false end function RemoveTableFromTable(original,remover) for _,v in ipairs(remover) do if table.HasValue(original,v) then table.Remove(GetKeyFromValue(original,v)) end end end[/lua]
Depends on what you mean. [lua] Table1 = { Prop1 , Prop2 , Prop3 , Prop4} Table2 = {Prop1 , Prop2 , Prop4} for k,v in pairs( Table2 ) do for a,b in pairs( Table1 ) do if v == b then Table1[a] = nil end end end [/lua] This removes any entries that are the same on both table1 and table2.
Thanks for you help guys , that's exactly what I was talking about.
Sorry, you need to Log In to post a reply to this thread.