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: How do you sort this table from least to greatest?

Previous Thread :: Next Thread 
iiAu is not online. iiAu
Joined: 27 Sep 2015
Total Posts: 86
04 Feb 2017 10:34 PM
You can't use table.sort on a table like this, a table of tables!

local table = {{5, "t"},{3, "x"},{2, "y"},{4, "n"},{1, "m"}}

You're supposed to sort the first index of every table from least to greatest, in this case the numbers

I don't know anything like metatables or anything to sort this. Give a little help?


Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
04 Feb 2017 10:35 PM
Insert the indexes into a table and sort it.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
04 Feb 2017 10:37 PM
table.sort(t,function(a,b) return #### < b[1] end)
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
04 Feb 2017 10:37 PM
Don't do that...

local table = {{5, "t"},{3, "x"},{2, "y"},{4, "n"},{1, "m"}}

table.sort(table, function(a, b)
return a[1] < b[1]
end)


Report Abuse
iiAu is not online. iiAu
Joined: 27 Sep 2015
Total Posts: 86
04 Feb 2017 10:37 PM
But then I would need to refer back to the table... If I were to create another table and then have it be sorted and have all that information being copied back on to those tables, that would be a lot of work. And a little unneat, maybe.


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
04 Feb 2017 10:37 PM
hashes are a[1]


Report Abuse
iiAu is not online. iiAu
Joined: 27 Sep 2015
Total Posts: 86
04 Feb 2017 10:38 PM
Oh, neato! I wasn't seeing the posts. Thank you


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
04 Feb 2017 10:38 PM
i win i replied with an answer first


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