Hello.
Hi all. We have a table with objects:
Code: Select all
objectsArray = {objectOne, objectTwo, objectThree ...}
This called a "list" or "numerically indexed" table.
We don't call tables "arrays", because array is a C thing and if you do then the Lua goblins will come after you at night.
Note that it doesn't really matter what type of elements are contained in the list.
The only thing that matters is that there is no "nil" in the list:
Code: Select all
list = { 1,2,3,4,5,6,7,8 } -- classic list
We can add new elements or remove the last element from this list using:
Code: Select all
list[#list] = nil -- remove last
list[#list + 1] = element -- insert
Just don't assign "nil" in the middle of the list because it will introduce gaps and will no longer be a proper list.
If you want to add/remove something in the beginning or middle of the list, use:
Code: Select all
table.remove(list, index) -- remove first
table.insert(list, index, element) -- insert
The rest of what you are describing doesn't make much sense.
What is your code trying to do?
One common approach is to have two lists: "active" and "inactive" and to move elements between the two lists.
But if each of your elements already has an "active" flag, then you shouldn't need to move elements around.