|
| 09 Jan 2017 02:00 PM |
Hello,
How would I go about inserting children into a table to edit them all in one go? For example instead of having to edit B1 & B2 separately I could combine them into one table and edit them both at the same time?
B1 = game.Workspace.Bulbs1:GetChildren() B2 = game.Workspace.Bulbs2:GetChildren()
Many thanks Curry
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 09 Jan 2017 02:03 PM |
| Iterate over B2 and push all the values onto B1 |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2017 02:13 PM |
How would I do that?
Thanks |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2017 02:15 PM |
for _,each in pairs(B2) do table.insert(B1,each) end |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2017 02:25 PM |
Okay if I wanted to add more say like,
B1 = game.Workspace.Bulbs1:GetChildren() B2 = game.Workspace.Bulbs2:GetChildren() B3 = game.Workspace.Bulbs3:GetChildren() B4 = game.Workspace.Bulbs4:GetChildren()
Would I just do this?
for _,each in pairs(A2, A3, A4) do table.insert(A1,each) end
Many thanks Curry |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 09 Jan 2017 02:34 PM |
You'll have to use multiple loops or put all the tables in a table and do it like that.
local function join(s, ...) local v = { ... } for idx = 1, #v do local a = v[idx] for idx = 1, #a do s[#s + 1] = a[idx] end end return s end
for i, v in ipairs(join(B1, B2, B3, B4)) do print(v) end |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 10:42 AM |
Iv tried to get this to work but it wont
Could you provide it in a example please?
Many thanks |
|
|
| Report Abuse |
|
|
Swordlust
|
  |
| Joined: 05 Dec 2016 |
| Total Posts: 476 |
|
|
| 10 Jan 2017 10:56 AM |
local B1 = workspace.Model:GetChildren() local B2 = workspace.Model2:GetChildren()
local table = { B1; B2; }
local table2 = { }
for _,v in pairs(table) do table.insert(table2, v) end
|
|
|
| Report Abuse |
|
|
Swordlust
|
  |
| Joined: 05 Dec 2016 |
| Total Posts: 476 |
|
|
| 10 Jan 2017 10:57 AM |
See what I just did there? lool
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 12:13 PM |
Why do I need Table2?
If I do,
local B1 = workspace.Model:GetChildren() local B2 = workspace.Model2:GetChildren()
local table = { B1; B2; }
Would that mean all the parts from Model and Model2 are inside the table?
many thanks curry |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 10 Jan 2017 01:54 PM |
local m1 = workspace.Model1:GetChildren() local m2 = workspace.Model2:GetChildren() local t = {}
for i,v in next, m1 do table.insert(t,v) end for i,v in next, m2 do table.insert(t,v) end
for i,v in next, t do print(i,v) end
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 10 Jan 2017 02:01 PM |
you can also do this. cntkilme's method is gross
local m1 = workspace.Model1:GetChildren() local m2 = workspace.Model2:GetChildren()
insert = function(...) local t,new = {},{...} for i,v in next, new do for k,c in next, v do table.insert(t,c) end end return t end
for i,v in next, insert(m1,m2) do print(i,v) end
|
|
|
| Report Abuse |
|
|