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
|
  |
 |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 11 Sep 2013 07:18 AM |
| Some Noob's just cant script e.e |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 11 Sep 2013 07:22 AM |
| i Joined.. t o ask Tenal.. how to equip gun's |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
| |
|
| |
|
|
| 11 Sep 2013 03:56 PM |
| Dpont criticise beginers i wana no'w how to equip Gun's |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
| |
|
|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
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
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|