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: Insert into table?

Previous Thread :: Next Thread 
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
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 is not online. 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
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
09 Jan 2017 02:13 PM
How would I do that?

Thanks
Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
09 Jan 2017 02:15 PM
for _,each in pairs(B2) do
table.insert(B1,each)
end
Report Abuse
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
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 is not online. 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
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
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 is not online. 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 is not online. Swordlust
Joined: 05 Dec 2016
Total Posts: 476
10 Jan 2017 10:57 AM
See what I just did there? lool


Report Abuse
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
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
IAmCurryV1 is not online. IAmCurryV1
Joined: 05 Nov 2016
Total Posts: 6
10 Jan 2017 01:32 PM
Bump
Report Abuse
TimeTicks is not online. 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 is not online. 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
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