|
| 27 Mar 2013 03:06 PM |
Does anybody have a function that alphabetizes objects in a table by their names? Example:
local NewTable = Alphabetize(Workspace:GetChildren())
The NewTable table would have the objects in alphabetical order. If anybody has one, I would really appreciate you giving it to me. It would save me some time on my project. |
|
|
| Report Abuse |
|
|
BAUER102
|
  |
| Joined: 03 Apr 2010 |
| Total Posts: 5936 |
|
|
| 27 Mar 2013 03:08 PM |
http://www.roblox.com/Alphabetation-Algorithm-Mid-2011-item?id=56023168
I'm pretty sure you can do something with this. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 27 Mar 2013 03:09 PM |
| Doesn't table.sort do this automatically? I believe the < and > operators do work on Lua strings such that "a" < "b" == true. |
|
|
| Report Abuse |
|
|
|
| 27 Mar 2013 03:10 PM |
@Dr01d
I never really looked into table.sort. I will check.
Oh, and, reported for spam. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 27 Mar 2013 03:17 PM |
I just had a quick thought and this may work, although I've never used table.sort: table.sort(workspace:GetChildren(), function (a, b) return (a.Name < b.Name); end); |
|
|
| Report Abuse |
|
|
|
| 27 Mar 2013 03:19 PM |
'I believe the < and > operators do work on Lua strings such that "a" < "b" == true.'
Sorcery! If this is true, it is epic!
However... it won't sort by second letter if the first letters are the same, unless the < and > do that.
If they don't, you need to provide a recursive function for the table.sort to sort by second letter if the first is the same, and so on. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 27 Mar 2013 03:21 PM |
http://www.lua.org/pil/3.2.html We can apply the order operators only to two numbers or to two strings. Lua compares numbers in the usual way. Lua compares strings in alphabetical order, which follows the locale set for Lua. For instance, with the European Latin-1 locale, we have "acai" < "açaí" < "acorde". Other types can be compared only for equality (and inequality). |
|
|
| Report Abuse |
|
|
|
| 27 Mar 2013 03:23 PM |
'it won't sort by second letter if the first letters are the same'
OK... it does.
Nice! The more you know.... |
|
|
| Report Abuse |
|
|