generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to clear a table?

Previous Thread :: Next Thread 
TehGabeNewell is not online. TehGabeNewell
Joined: 07 Feb 2013
Total Posts: 3165
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 is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
14 Jun 2015 12:50 AM
tableName = {}

Simple
Report Abuse
TehGabeNewell is not online. TehGabeNewell
Joined: 07 Feb 2013
Total Posts: 3165
14 Jun 2015 12:51 AM
o wow ok thx.
Report Abuse
Goulstem is not online. 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 is not online. 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 is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
14 Jun 2015 01:42 AM
oh here comes the efficiency arguments
Report Abuse
TehGabeNewell is not online. TehGabeNewell
Joined: 07 Feb 2013
Total Posts: 3165
14 Jun 2015 01:54 AM
@cnt and goul

you killed by brain, i didn't understand those lol
Report Abuse
iiEssence is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image