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: Cloning a table in 1 line.

Previous Thread :: Next Thread 
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 12:55 AM
I was bored and looking in the past, I saw a lot of posts about how to clone a table, and they were long.

I just tested this and it worked (if you already knew this, sorry for wasting your time):
local MainTable = {Blah, blah, blah}
local Clone = {unpack(MainTable)}
Report Abuse
LPGhatguy is not online. LPGhatguy
Forum Moderator
Joined: 27 Jun 2008
Total Posts: 4725
11 Sep 2013 12:59 AM
This only copies the array portion.

    local from = {a = 1}
    local to = {unpack(from)}

to is still empty
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 01:01 AM
Yeah, I know. But I was talking about indexed-based tables.
But I wonder if I can find out a tiny script to clone any kind of table, it will probably be easy.
Just a for loop and table[Index]=Child.
Okay, 3 lines.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 01:07 AM
So pretty much, to clone any table, you can do:

local Table = {}
local Clone = {}

for Index, Value in next, Table do
Clone[Index] = Value
end

Correct?
Report Abuse
SN0X is not online. SN0X
Joined: 24 Oct 2011
Total Posts: 7277
11 Sep 2013 05:45 AM
it's easy to do in one line

local Table = {}
local Clone = {}

for Index, Value in next, Table do Clone[Index] = Value end


#WIN #BOSS #YOLO #SWAG #YOLOSWAG
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
11 Sep 2013 05:54 AM
well, that's not advance but still a discussion which you answered... but ok
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
11 Sep 2013 07:15 AM
tab1 = {'hi', 'noob'}

setmetatable(tab1, {
__add = function(t1, t2)
for i, v in pairs(t1) do
t2[i] = v
end

return t2
end
})


tab2 = tab1 + {}
print(unpack(tab2)) --> hi noob
Report Abuse
TaskScheduler is not online. TaskScheduler
Joined: 14 May 2013
Total Posts: 497
11 Sep 2013 07:18 AM
Some Noob's just cant script e.e
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
11 Sep 2013 07:20 AM
'Haze Corporation'

"Some Noob's just cant script e.e "
"Some Noob's"
"Noob's"

HOW ABOUT NO?
Report Abuse
TaskScheduler is not online. TaskScheduler
Joined: 14 May 2013
Total Posts: 497
11 Sep 2013 07:22 AM
i Joined.. t o ask Tenal.. how to equip gun's
Report Abuse
SN0X is not online. SN0X
Joined: 24 Oct 2011
Total Posts: 7277
11 Sep 2013 08:04 AM
u need an LAU.
Report Abuse
wateraurahf is not online. wateraurahf
Joined: 08 Sep 2013
Total Posts: 109
11 Sep 2013 02:40 PM
[ Content Deleted ]
Report Abuse
TaskScheduler is not online. TaskScheduler
Joined: 14 May 2013
Total Posts: 497
11 Sep 2013 03:56 PM
Dpont criticise beginers i wana no'w how to equip Gun's
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
11 Sep 2013 04:08 PM
Get out.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
11 Sep 2013 04:15 PM
'Dpont criticise beginers i wana no'w how to equip Gun's'

'Dpont'
>NOPE

'beginers'
>NOPE

'wana no'w'
>NOPE

'Gun's''
>NOPE
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 05:36 PM
Biggest derailment ever.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
11 Sep 2013 06:01 PM
[ Content Deleted ]
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 06:03 PM
How is this thread stupid, I never saw anyone do this before so I'm helping, moron.
Report Abuse
Merilo is not online. Merilo
Joined: 01 Aug 2011
Total Posts: 500
11 Sep 2013 06:09 PM
Hey, moron is a fighting word.

daily lesson from cat
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
11 Sep 2013 06:39 PM
[ Content Deleted ]
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 06:43 PM
Faulty?

I never had questions, I just saw more than 10 threads talking about this.
And I see like more than 10 line answers, from regulars.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
11 Sep 2013 06:53 PM
[ Content Deleted ]
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 06:56 PM
"Correct?" is more or less a question, I guess.

Also, did you mean: it copies all the values from a table and puts it in another?
I guess it's not ACTUALLY copying, but not sure exactly what you mean.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Sep 2013 07:00 PM
I guess "get" would be a better word in this case.
It "gets" all the values from a table and just adds them in another.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
11 Sep 2013 07:22 PM
[ Content Deleted ]
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