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 » Scripting Helpers
Home Search
 

Re: Combining tables

Previous Thread :: Next Thread 
LEG0builder is not online. LEG0builder
Joined: 06 Jun 2008
Total Posts: 3188
29 Dec 2011 12:00 PM
Is there a specific function for that? I know it would be possible to use a loop to add each element one at a time, but it sounds kinda messy. Like:
a = {1,2,3,4}
b = {5,6,8,0}
I just need to make a table like {1,2,3,4,5,6,8,0}....
Report Abuse
NeonBlox is not online. NeonBlox
Joined: 19 Oct 2008
Total Posts: 1462
29 Dec 2011 12:04 PM
Maybe something like this?

a = {1,2,3,4}
b = {5,6,8,0}
c = {}

for i,v in pairs(a) do
c[i] = v
end
for i = 5,v in pairs(b) do
c[i] = v
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
29 Dec 2011 12:06 PM
Do you mean table.concat?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
29 Dec 2011 01:46 PM
Use metatables and the __add metamethod.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
29 Dec 2011 01:51 PM
local TableA = {1, 2, 3}
local TableB = {4, 5, 6}

local Meta = {
__add = function(table1, table2)
local ToReturn = {}
for _, v in next, table1 do
ToReturn[_] = v
end
return ToReturn
end})
setmetatable(TableA, Meta)
setmetatable(TableB, Meta)

for _, v in next, TableA + TableB do
print(v)
end

> 1
> 2
> 3
> 4
> 5
> 6
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
29 Dec 2011 01:55 PM
Mine is reduntant. Never mind, just use a for loop, unless you'll have to combine them a lot.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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