|
| 24 Dec 2013 02:55 PM |
-- function table_remove(tabl, str) for i = 1, #tabl do if tabl[i] == str then table.remove(tabl, i) end end end --
~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~ |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Dec 2013 02:58 PM |
Example of use -- t = {"Person", "Person2", "Person3"} table_remove(t, "Person3") print(unpack(t)) -- >Person Person2
~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~ |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Dec 2013 03:00 PM |
| You would probably want to break it after it removes it otherwise it will remove all values with the same name |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Dec 2013 03:02 PM |
| You could specify the number of times the string will be removed as a third argument, so if you only wanted to remove 1 then you can say so. |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 03:03 PM |
-- function table_remove(tabl, str) for i = 1, #tabl do if tabl[i] == str then table.remove(tabl, i) break end end end -- Happy, cnt?
~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~ |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 03:05 PM |
function table_remove(tabl, str, count) for i = 1, #tabl do if tabl[i] == str and count > 0 then table.remove(tabl, i) count = count - 1 if count == 0 then -- Optional if statement for very large tables break end end end end
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
| |
|
HaxHelper
|
  |
| Joined: 19 Dec 2009 |
| Total Posts: 1208 |
|
|
| 24 Dec 2013 04:05 PM |
| is this what the scripter forum has turned into |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Dec 2013 05:39 PM |
| Why not keep all the values and declare the unused values nil? |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 05:45 PM |
| This function will not have the desired behaviour when two matches are adjacent. The table has to be iterated in reverse when items are being removed during the iteration. |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 24 Dec 2013 08:02 PM |
| I think using table.remove is just easier. |
|
|
| Report Abuse |
|
|