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: table.sort help

Previous Thread :: Next Thread 
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
20 Sep 2015 05:16 PM
I have never used table.sort and never understood it,
how can I sort a table from high to low value of a property of the table
I need the highest rap to be at the top
the table looks would like this

Stuff = {
Item = {Product = {Rap = 194,Name = "a name of something",morestuff = "blah"}}
Item = {Product = {Rap = 4234,Name = "a name of somethingelse",morestuff = "blahaa"}}
Item = {Product = {Rap = 14254,Name = "a name of something",morestuff = "blaaffh"}}
}

Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
20 Sep 2015 05:17 PM
I forgot the ", between the tables"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:18 PM
The keys replace each other so what you're doing with that Stuff table is a waste of time, in the end you'll only have 1 pair, not 3.

And table.sort only sorts arrays, dictionary-part of the array has no 'order' so you can't sort it.
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
20 Sep 2015 05:19 PM
table.sort(stuff,function(a,b)
return a.Rap > b.Rap
end)
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
20 Sep 2015 05:20 PM
Wait so the above thing wouldn't work?? :(
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:23 PM
No
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
20 Sep 2015 05:24 PM
@cnt How DOES the second argument to table.sort work?? If it returns true then a > b if not then b>a ??
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:25 PM
If it returns true, it puts a in front of b, otherwise it puts b in front of a.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
20 Sep 2015 05:26 PM
dont you just love LUA
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
20 Sep 2015 05:28 PM
Oh cool!
Also what's the problem with string indexes?? Since tab[1] and tab[str] are pretty similar???
tab = {"a","b"}
tab = {str = a,str2 = b}
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:28 PM
Yes, Lua is a fantastic language. People who don't like Lua are generally bad at it and don't understand how anything works.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:29 PM
Because as I said before, dictionaries don't have any order. They way hashmaps are generally implemented makes it so you can't actually order them.
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
20 Sep 2015 05:44 PM
table.sort(Stuff,function(a,b)
return a.Product.Rap > b.Product.Rap
end)

that works for me?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:45 PM
You think it works, but it's not.
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
20 Sep 2015 05:47 PM
so the fact I looped through it printing rap in order its still is not sorted?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Sep 2015 05:50 PM
It's not, stop lying.
The most obvious reason being keys are unique, when you create your table there is only 1 pair inside, not 3.
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