|
Would this work?
for i,v in pairs(_G.alive) do
table.remove(_G.alive, i)
end |
|
|
I thought this would be an easy question.. |
|
|
Well, because if how tables work, clearing the table is actually easy, depending on how you want it cleared.
You could reset the variable;
X = {"Hi"}
X = {}
And let the garbage collector remove {"Hi"} after a while,
However, if your using _G then you could use that above script.
However, I do not think that would reduce the size, but whatever reason you're doing this, that should not matter. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
function clear(tab)
for k,v in pairs(tab) do
tab[k] = nil
end
end
empty tables that you add on to later will not be cleared by merely "resetting the variable" |
|
|
@Dueling
I said the gc would collect it eventually, and besides your code might clear it, but the size of the table will not be reduced. You could overload it with a ton of nils to do this, but there's no telling how many it would take. |
|
|
By the way, when I said the above script I meant OP lol. |
|
|
If the table was in a while loop, and I called functions that added players to the table, would it reset the table each time the loop ran? |
|
|
Or just use PlayerAdded... |
|
|
It's a round loop, It runs the round if game.Players.NumPlayers >1, so would it reset the table each time the loop runs? |
|
MrNicNacJoin Date: 2008-08-29 Post Count: 28554 |
Yes, OP, your script would work fine if all you did was add the players like:
table.insert(_G, player) |
|
|
Saying table.remove(_G.alive, i) would work? Or would it be; table.remove(_G.alive, _G.alive[i]) |
|
MrNicNacJoin Date: 2008-08-29 Post Count: 28554 |
Just i |
|
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
@war
My code destroys tables within the table and dictionaries.
It's fine, tyvm. |
|
|
@Duelling in most cases, yes, it would.
But it wouldn't reduce table size, and it would only remove the references to tables if the value inside is a table, it would not clear table values, think of using recursion for that problem.
I know of no way to reduce the table size. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
um it's called nil(oh hey nonexistant) and gc |
|
|
Uh yeah, what if someone made another reference, think before you script. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
"if someone"
Why would I be thinking about others lol? |
|
|
...
As long as this would work I'm fine.
for i,v in pairs(_G.alive) do
table.remove(_G.alive, i)
end |
|
|
So you're admitting you're greedy and selfish. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
No I am admitting that I don't steal scripts since I know what is completely going on the entire time. |
|
|