I am running through a list of items, and if one of them has a certain quality, I remove it from the table. Whenever an item gets removed from the table, the following items decrease their index by one, thus skipping items. How can I get around this problem?
Can you provide some code? I assume what you’re doing is…
for i = 1, #t do
if something then
table.remove(t, i)
end
end
If it’s something like that, you can just run the loop in reverse to avoid this issue.
for i = #t, 1, -1 do
if something then
table.remove(t, i)
end
end
3 Likes