Say I want to add a value to a table.
table = {} table.insert(table, "remove me") table.insert(table, "keep me") table.insert(table, "1") table.insert(table, "3")
Now I want to remove a certain value from a table.(pretend I don't know the order of the table)
for i, v in pairs(table) do if table[i] == "remove me" then table.remove(table, i) end end
I don't know why but when searching through a table like this where the values aren't set to something else I prefer to sue this method
for i=1, #table do if table[i] == "remove me" then table.remove(table, i) end end
Also I don't recommend using "table" as the name of your table as it could cause some confusion
Hope this helped!
You did table.insert correctly.
mytable = {} -- table is a syntax table.insert(mytable, "remove me") table.insert(mytable, "keep me") table.insert(mytable, "1") table.insert(mytable, "3")
Now how do we do table.remove?? table.remove() has two arguments. The first one is the table. The next one is the index. In the second script you will see how to use table.remove()
--Insert-- mytable = {} -- table is a syntax table.insert(mytable, "remove me") print(mytable[1]) table.insert(mytable, "keep me") table.insert(mytable, "1") table.insert(mytable, "3") --Remove-- wait(2) table.remove(mytable,1) -- The first index was a string and it was "remove me" right?? Now it will be deleted from the table myTable print(myTable[1]) -- Now the first index is now the string "keep me", So the results are now supposed to be "keep me"
Hopefully that is a very detailed answer to your question!! Please submit this answer if it worked!