Vadi wrote:Hm, no, you'd be looping in another loop that removes entries from a different table.
I'm not sure if your way will continue iterating properly...
Correct me if I'm wrong, but I thought you meant something like:
local bad_indices = {}
for i,v in ipairs(mytable) do
if v == "somevalueIdon'tlike" then bad_indices[#bad_indices+1]=i end
end
for _,v in ipairs(bad_indices) do
table.remove(mytable, v)
end
If that's what you meant, wouldn't that still give you the same problem?
If I have the table {"foo", "somevalueIdon'tlike", "bar", "somevalueIdon'tlike"} it would first make the bad_indices table: {2,4}. So far so good.
Then it would go through that table, and first do table.remove(mytable, 2), resulting in the table {"foo", "bar", "somevalueIdon'tlike"}.
Then it would do table.remove(mytable,4), but since mytable no longer has an index 4, it wouldn't do anything, and we'd end up with the table {"foo", "bar", "somevalueIdon'tlike"}.
I'm pretty sure my method would work, since I've used something similar a few times before.