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: Sorting tables...

Previous Thread :: Next Thread 
Rocky28447 is not online. Rocky28447
Joined: 11 Dec 2009
Total Posts: 2912
14 Sep 2015 09:16 PM
How would one sort a table of strings alphabetically?


choo choo
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 09:17 PM
The table.sort function should do exactly what you want.

table.sort(YourTable)
Report Abuse
MKofOrbiter is not online. MKofOrbiter
Joined: 28 Aug 2010
Total Posts: 910
14 Sep 2015 09:18 PM
^

You didn't even use it right.
Report Abuse
Rocky28447 is not online. Rocky28447
Joined: 11 Dec 2009
Total Posts: 2912
14 Sep 2015 09:21 PM
I didn't even though there was such a thing!
TO THE WIKI! TIME FOR EXTENSIVE RESEARCH!


choo choo
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
14 Sep 2015 09:21 PM
@MK could you explain to me how a "comp" (the second arg) works? like
function(a,b)
if a > b then
return true
else
return false
end
end

Like that??
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 09:22 PM
Yes I did. The second argument is optional, and the table of strings will be sorted lexically.
Report Abuse
Rocky28447 is not online. Rocky28447
Joined: 11 Dec 2009
Total Posts: 2912
14 Sep 2015 09:25 PM
What if it was say, numbers? Can you give me an example of how to sort the numbers from largest to smallest and smallest to largest?


choo choo
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Sep 2015 09:31 PM
To sort it from smallest to largest:

table.sort(YourTable, function(a, b)
return a < b
end)

And largest to smallest:

table.sort(YourTable, function(a, b)
return a > b
end)
Report Abuse
lostend is not online. lostend
Joined: 21 Aug 2011
Total Posts: 8265
14 Sep 2015 09:38 PM
string:sub(1,1):lower():byte()

returns ascii equivalent I believe
the less it is, the closer to a.
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