Currently I am trying to get the first item in a table and remove it.
So far this is the only way I have thought of to do it:
[code]
if (tbl && #tbl > 200) then
for k, v in ipairs(tbl) do
v:Remove();
table.remove(tbl, k);
break;
end
end
[/code]
It does work, but I was wondering if there was a better way to do this.
I was also wondering if there was a way to move all items in a sequential table down to fill in gaps.
Here's an example:
I have the table:
[code]
1 = hi
2 = bye
3 = cya
4 = welcome back
[/code]
Lets say I removed 2(bye) from the table. Would there be a way to move down 3 and 4 to fill in the blanks to make the table sequential again?
Thanks.
table.remove already shifts all elements in the table down. If you are just looking to remove the first element, you can just do:
[code]tbl[1]:Remove() -- Will only work if it's an entity
table.remove(tbl, 1)[/code]
[QUOTE=code_gs;51756225]table.remove already shifts all elements in the table down. If you are just looking to remove the first element, you can just do:
[code]tbl[1]:Remove() -- Will only work if it's an entity
table.remove(tbl, 1)[/code][/QUOTE]
Thank you!
I wasn't aware that table.remove shifted everything down already, I thought it just removed the item from the table and left everything the way it was.
Sorry, you need to Log In to post a reply to this thread.