|
| 14 Jun 2015 12:46 AM |
| ok so say i have a table that stores players names, how would i clear it so it has no names? |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
| |
|
| |
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Jun 2015 01:29 AM |
local table = setmetatable({},{__index = table});
table.clear = function(tab) tab = {}; end
ur walcome |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 14 Jun 2015 01:34 AM |
that's not gonna work lol,
for key in next, tab do tab[key] = nil end |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 14 Jun 2015 01:42 AM |
| oh here comes the efficiency arguments |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 01:54 AM |
@cnt and goul
you killed by brain, i didn't understand those lol |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 14 Jun 2015 01:56 AM |
| I kept it simple and dirty by creating a new address while they are trying to do it the efficient way by actually clearing the address. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Jun 2015 02:08 AM |
"for key in next, tab do tab[key] = nil end"
That will just set the indexes to nil, they're still there just instead of
tab = {1,5,true,'hi'};
it's
tab = {nil,nil,nil,nil}
Why not just create a new table?
tab = {} |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 14 Jun 2015 02:19 AM |
| Your way creates a new table that is unreachable is what I'm trying to say. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Jun 2015 02:39 AM |
| But won't the unusable table just get GC'd? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 14 Jun 2015 02:41 AM |
Exactly, so you're essentially doing nothing lol.
|
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Jun 2015 02:43 AM |
Oh you're saying that
tab = {}
is the table that becomes unusable?
I thought you meant the previous table that was assigned to 'tab' became unreachable. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 14 Jun 2015 02:44 AM |
| oh sorry, yeah that new table you create inside is just lost |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Jun 2015 02:45 AM |
well dang
for i,v in pairs(tab) do tab[i] = nil; end |
|
|
| Report Abuse |
|
|