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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Tables

Previous Thread :: Next Thread 
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 05:12 PM
So, below I have table1 and table2:

table1 = {{number = 1}, {number = 10}, {number = 100}}
table2 = {{number = 2}, {number = 20}, {number = 200}}

I want to combine them into Table3, but have them organized by their number keys. I want this:

table3 = {{number = 1}, {number = 2}, {number = 10}, {number = 20}, {number = 100}, {number = 200}}

And NOT this:

table3 = {{number = 1}, {number = 10}, {number = 100}, {number = 2}, {number = 20}, {number = 200}}


How in the world could I organize these? I'm clueless. Thanks!
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Feb 2014 05:14 PM
Here:

for i = 1, #table1 do
table.insert(table3, table1[i])
if table2[i] then table.insert(table3, table2[i]) end
end
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 05:16 PM
That could work, but I want it to work with any possible number combination.

5, 40, 700
2, 45, 600

^
Wouldn't work, for example.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Feb 2014 05:20 PM
table.sort and do something like this:

table1 = {1, 2, 5}
table2 = {3, 4, 0}
table3 = {unpack(table1), unpack(table2)}
table.sort(table3)
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
05 Feb 2014 05:20 PM
check the values in table 3. run through a few loops to find the number above and below the number you want to table.insert, then insert them there.
Report Abuse
Preponderance is not online. Preponderance
Joined: 30 Sep 2009
Total Posts: 21293
05 Feb 2014 05:20 PM
Put them in table3 and use
table.sort(table3)
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
05 Feb 2014 05:22 PM
or table.sort
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 05:27 PM
I really don't know if that will work...

You see, I have 3 very large JSON objects.

[{String:"Cat", Number:45},{Name:"Aardvark", Number:2}, ... ]

It goes on and on...

I want to merge and sort basically. I can merge it very easily, but I have no clue how to sort... I figured that decoding to a Lua table and back would help resolve the problem.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Feb 2014 05:27 PM
I already gave you the script you could use assuming tables were like so:
table1 = {#,#,#}
table2 = {#,#,#}
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 05:38 PM
Doesn't work, you try it.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Feb 2014 05:48 PM
I did, you are doing it wrong
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 07:44 PM
So you mean to tell me that I can decode these JSON objects

http://www.roblox.com/catalog/json?Subcategory=16&SortType=3&ResultsPerPage=10
http://www.roblox.com/catalog/json?Subcategory=9&SortType=3&ResultsPerPage=10

Put them in one table, sort them by one of the number-related keys, and put it back in a JSON table?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Feb 2014 07:44 PM
-.- yes, easily
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
05 Feb 2014 08:48 PM
Alright, then what could I be doing wrong?:

json1 = '[{"AssetId":142487777,"Name":"Somebody Call My Momma (2minversion)","Description":"Audio","Url":"/Somebody-Call-My-Momma-2minversion-item?id=142487777","PriceInRobux":"","PriceInTickets":"","Updated":"19 minutes ago","Favorited":"0 times","Sales":"0","Remaining":"","Creator":"NaomiKnight","CreatorUrl":"/User.aspx?ID=46774612","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":46774612,"CreatedDate":"\/Date(1390006750613)\/","UpdatedDate":"\/Date(1391650058635)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":145127587,"Name":"m.A.A.d City- Kendrick Lamar","Description":"Where you at? Where you from?\r\n\r\nLil Wayne, Rich Homie Quan, Rap, Hip Hop, Young Money, Rich Gang, Future, Miley Cyrus, Drake, Nicki Minaj, Trey Songs, Ghetto, Hard, Bars, Barz, Rick Ross, Kendrick Lamar, A$ap Rocky, Asap, Cheif Keef.","Url":"/m-A-A-d-City-Kendrick-Lamar-item?id=145127587","PriceInRobux":"","PriceInTickets":"","Updated":"40 minutes ago","Favorited":"0 times","Sales":"1","Remaining":"","Creator":"lionhart12","CreatorUrl":"/User.aspx?ID=16424036","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":16424036,"CreatedDate":"\/Date(1391647074212)\/","UpdatedDate":"\/Date(1391648756444)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":145129131,"Name":"Heavy D & The Boyz - Now That We Found Love","Description":"Audio","Url":"/Heavy-D-The-Boyz-Now-That-We-Found-Love-item?id=145129131","PriceInRobux":"","PriceInTickets":"","Updated":"46 minutes ago","Favorited":"0 times","Sales":"0","Remaining":"","Creator":"MtEden","CreatorUrl":"/User.aspx?ID=18560924","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":18560924,"CreatedDate":"\/Date(1391647755563)\/","UpdatedDate":"\/Date(1391647755579)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":130865948,"Name":"Spelunky: Ultra Egg","Description":"Aka Eggplant theme song\r\n\r\nEdit: Apparently this song was used in a Roblox Snowboarding game, thus is in the Roblox Winter Games? That\u0027s cool I guess.","Url":"/Spelunky-Ultra-Egg-item?id=130865948","PriceInRobux":"","PriceInTickets":"","Updated":"46 minutes ago","Favorited":"5 times","Sales":"48","Remaining":"","Creator":"millsbuddy","CreatorUrl":"/User.aspx?ID=351141","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":351141,"CreatedDate":"\/Date(1380259444873)\/","UpdatedDate":"\/Date(1391648398303)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":145129113,"Name":"Animals Martin Garrix","Description":"This is the song animals I did not make the song also this is part one of the song ill upload part 2 soon. 2 minutes long.\r\n\r\nLink to video\r\nhttp://www.youtube.com/watch?v=gCYcHz2k5x0","Url":"/Animals-Martin-Garrix-item?id=145129113","PriceInRobux":"","PriceInTickets":"","Updated":"54 minutes ago","Favorited":"0 times","Sales":"1","Remaining":"","Creator":"TheMostWantedPerson","CreatorUrl":"/User.aspx?ID=47132393","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":47132393,"CreatedDate":"\/Date(1391647751333)\/","UpdatedDate":"\/Date(1391647958871)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0}]'
json2 = '[{"AssetId":145135685,"Name":"Body swap potion","Description":"Please buy it. Friend me.","Url":"/Body-swap-potion-item?id=145135685","PriceInRobux":"","PriceInTickets":"","Updated":"2 minutes ago","Favorited":"0 times","Sales":"1","Remaining":"","Creator":"Froaty","CreatorUrl":"/User.aspx?ID=54763648","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":13,"CreatorID":54763648,"CreatedDate":"\/Date(1391650765736)\/","UpdatedDate":"\/Date(1391651027658)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":145091741,"Name":"Ancient Golem","Description":"used to protect josh\u0027s castle...these brutes are strong enough to toss a 5-ton truck...","Url":"/Ancient-Golem-item?id=145091741","PriceInRobux":"","PriceInTickets":"","Updated":"12 minutes ago","Favorited":"0 times","Sales":"0","Remaining":"","Creator":"Creepypasta123","CreatorUrl":"/User.aspx?ID=29892030","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":13,"CreatorID":29892030,"CreatedDate":"\/Date(1391631237812)\/","UpdatedDate":"\/Date(1391650447401)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":142663097,"Name":"Apollo ","Description":"","Url":"/Apollo-item?id=142663097","PriceInRobux":"","PriceInTickets":"","Updated":"12 minutes ago","Favorited":"0 times","Sales":"1","Remaining":"","Creator":"poptartcat123456789","CreatorUrl":"/User.aspx?ID=20932568","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":13,"CreatorID":20932568,"CreatedDate":"\/Date(1390099254210)\/","UpdatedDate":"\/Date(1391650430103)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":144941001,"Name":"meulin and kurloz","Description":"i can\u0027t do kurloz\u0027s horns! D:\r\n\r\nbase owner: idk who","Url":"/meulin-and-kurloz-item?id=144941001","PriceInRobux":"","PriceInTickets":"","Updated":"17 minutes ago","Favorited":"0 times","Sales":"0","Remaining":"","Creator":"GoodChiuaua","CreatorUrl":"/User.aspx?ID=8125645","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":13,"CreatorID":8125645,"CreatedDate":"\/Date(1391482354537)\/","UpdatedDate":"\/Date(1391482411057)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0},{"AssetId":145134270,"Name":"TRC Valentines","Description":"","Url":"/TRC-Valentines-item?id=145134270","PriceInRobux":"","PriceInTickets":"","Updated":"18 minutes ago","Favorited":"0 times","Sales":"0","Remaining":"","Creator":"FedoraMasterB98","CreatorUrl":"/User.aspx?ID=10271988","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":13,"CreatorID":10271988,"CreatedDate":"\/Date(1391650097271)\/","UpdatedDate":"\/Date(1391650097271)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0}]'
local Utils = assert(LoadLibrary("RbxUtility"))
table1 = Utils.DecodeJSON(json1)
table2 = Utils.DecodeJSON(json2)
table3 = {}
nums = {}
items = {}
for i=1, #table1 do
table.insert(nums, table1[i].Number)
table.insert(items, table1[i])
end
for i=1, #table2 do
table.insert(nums, table2[i].Number)
table.insert(items, table2[i])
end
table.sort(nums)
for i=1, #nums do
for j=1, #items do
if items[j].Number == nums[j] then
table.insert(table3, items[i])
end
end
end
print (Utils.EncodeJSON(table3))
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
07 Feb 2014 06:41 PM
Nevermind, I have my own solution:

local table1 = {{Name = "Hello",Number = 1},{Name = "Bye",Number = 70},{Name = "Meow",Number = 40}}
local table2 = {}
local n = {}
local o = {}
for i=1, #table1 do
table.insert(n, table1[i].Number)
table.insert(o, table1[i])
end
table.sort(n)
for i=1, #n do
for j=1, #o do
if o[j].Number == n[i] then
table.insert(table2, o[j])
end
end
end
for i=1, #table1 do
print (table2[i].Number)
end
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