Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[ANSWERED] Is there an easier way to append items to a list?

Asked by 5 years ago
Edited 5 years ago

As of right now I am using table.insert(table, position in table, item) to add items to a table, and using a for loop to add things from another table to it, but I also have to add a counter to it so that for the position in the table it is always one more than the last. This seems tedious to me (even if it is only a couple lines) so I was wondering if there was anything similar to appendItem() from javascript that I just don't know about. I also couldn't find anything about it in the lua documentation. Thanks for any answers!

0
you could get the length of the table and add 1 to it and that would solve the issue of repetition you can access the table's length by using #(tablenamehere) and add 1 to it in parentheses. Mr_Pure 129 — 5y
0
table.Insert(MyTable, #MyTable + 1, item) Mr_Pure 129 — 5y
0
@Mr_Pure thanks, I might use that. I'll mark this question as answered. Would upvote but can't. msuperson24 69 — 5y
0
If you omit the position argument, it defaults to the index after the end of the list. RayCurse 1518 — 5y
0
@RayCurse Ah that's more straightforward than I figured, thanks msuperson24 69 — 5y

Answer this question