maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 17 Jul 2014 11:12 PM |
if you know the name and not the place?
table.remove () requires the place in the table as the second argument, but I don't know it. I just know the name. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 11:13 PM |
for n,v in pairs(tbl) do if v == "name" then table.remove(tbl, n) break end end |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
| |
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 17 Jul 2014 11:19 PM |
Roy, actually, it would change and remove the wrong things(I think).
tbl={} tbl2={} for n,v in pairs(tbl) do if n == "NAME" then table.insert(tbl2, n);--Actually this might result in the same way. end end tb2 = {}
|
|
|
| Report Abuse |
|
|
|
| 18 Jul 2014 12:09 AM |
| No, KEV, it wouldn't. I break the loop after I remove the single value. |
|
|
| Report Abuse |
|
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 18 Jul 2014 09:22 AM |
@Very, the only problem with that is that the object is a team and setting it to nil would destroy the team or possibly still be in the table just as a nil value.
The first poster's solution work like a charm. Thanks. |
|
|
| Report Abuse |
|
|
|
| 18 Jul 2014 09:28 AM |
@Max
Remember my plugin TULOF (The Ultimate List Of Functions)?
You should have checked that. I'm writing from memory but this was part of it;
function Table_Destroy(T, V) for I,v in pairs(T) do if v == V then table.remove(T, I) end end end |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 18 Jul 2014 06:07 PM |
I have yet to install it.
Ehh, I'll probz need it. |
|
|
| Report Abuse |
|
|
|
| 18 Jul 2014 07:13 PM |
XD
It only has a few functions. I haven't been around to updating it. |
|
|
| Report Abuse |
|
|
|
| 18 Jul 2014 07:19 PM |
local table_remove=function(tab,val) for i=1,#tab do if tab[i]==val then table.remove(tab,i) break end end end |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 18 Jul 2014 11:40 PM |
Oh, you forgot a break in that loop, war. #rekt
I really wasn't expecting this thread to last that long... |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2014 06:41 AM |
| I didn't forget the break. If you want a value gone from the table, why would you just remove the first one, and who's to say you wanted the FIRST one removed hmm? So for safety measures I removed them all. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 19 Jul 2014 09:38 PM |
what wow, what a loophole.
Next time I'll get ya, ya ol' coot! |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 19 Jul 2014 10:10 PM |
@War Yours doesn't work
function Table_Destroy(T, V) for I,v in pairs(T) do if v == V then table.remove(T, I) end end end
local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"} Table_Destroy(t, "Hello") print(unpack(t))
Output:Hello Hey Hi Hi
function rft(...) local t, v, s = unpack({...}) local s, S = (s == nil and math.huge or s), 0 local quarantine = {} for I, V in pairs (t) do if V == v and s > S then S = S + 1 table.insert(quarantine, I) end end for q = #quarantine, 1, -1 do table.remove(t, quarantine[q]) end return #quarantine end
local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"} rft(t, "Hello") --removes all print(unpack(t))
--[[Output Hey Hi Hi]]
local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"} rft(t, "Hello", 2) --removes only the first 2 print(unpack(t))
--[[Output Hey Hello Hi Hi]] |
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Jul 2014 06:52 AM |
Okay, here you go then.
function table_destroy(T, v) local X = 1 repeat if T[X] = v then table.remove(T, X) else X = X + 1 end until X == #T --Note; Will not work with dictionaries. See NumItems end
function NumItems(T) local n = 0 for I,v in pairs(T) do n = n + 1 end return n end
--^Use that for dictionaries. |
|
|
| Report Abuse |
|
|
UncleTaz
|
  |
| Joined: 19 Aug 2009 |
| Total Posts: 12795 |
|
|
| 20 Jul 2014 07:04 AM |
| Wow. All that just removing a object from table. |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2014 08:46 AM |
item[object] = nil
easy 4 dictionaries |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 20 Jul 2014 09:19 AM |
@War Still doesn't work
function table_destroy(T, v) local X = 1 repeat if T[X] == v then table.remove(T, X) else X = X + 1 end until X == #T --Note; Will not work with dictionaries. See NumItems end
local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi", "Hello"} table_destroy(t, "Hello") print(unpack(t))
Output Hey Hi Hi Hello |
|
|
| Report Abuse |
|
|