I wrote a small function that takes two tables, list1 and list2 and combines them. I use it for concatenating lists of enemies. Is there an easier way to do this?
function combinelists(list1 , list2)
index = {}
for i = 1, #list2 do
for v = 1, #list1 do
if list2[i] == list1[v] then
table.insert(index,i)
end
end
end
for i = 0, #index-1 do
table.remove(list2,index[#index-i])
end
for i = 1,#list2 do
table.insert(list1,list2[i])
end
return(list1)
end
function combinelists(l1, l2)
if typeof l1 ~= "table" or typeof l2 ~= "table" then return end
local list1 = l1
local list2 = l1
local index = {}
for i = 1, #list2 do
for v = 1, #list1 do
if list2[i] == list1[v] then
table.insert(index,i)
end
end
end
for i = 0, #index-1 do
table.remove(list2,index[#index-i])
end
for i = 1,#list2 do
table.insert(list1,list2[i])
end
return(list1)
end
Added a check to make sure that you're given tables, and localized the tables (see the tips section - localizing makes accessing them much faster)