I have a GUI menu with lots of GUI textbuttons, and currently they are placed pretty randomly (its a scrolling gui) and I would like to organize them Alphabetically via a script. I would like to include an attempt at this, but to be honest I have no earthly where to start since I don't know if there is even a function or way to do this. I assume I would need to put all the buttons in a table and then call some kind of function that places them in the scrolling frame according to their name but I'm not really sure. Would it involve assigning letters to numbers like A = 1 B = 2 Etc, and then having a set distance as a variable for the space between the buttons and adding a certain number of spaces depending on which number(letter) it is? If so how would I tell the script to recognize the first letter of each word? Sorry if this is confusing, let me know if I need to clarify anything. Thanks guys!
Recently (January 20th 2017), ROBLOX introduced a new instance type called UILayout
whose subclasses provide basic high-level layouts for GuiObjects like grids and lists.
Have a look at the API definition for UIListLayout on the Official ROBLOX Wiki.
It has some basic instructions about how to use it, but let me draw your attention to the SortOrder
field. One of the options for this is Custom
, which means you can specify your own sorting function. There is also a short description of how to setup your own sort function.
I've never used this before, so it's a tad experimental, but the gist of it is this:
UILayoutObject
as a sibling of the objects which you want to be listed alphabeticallyName
field of GuiObject
lexicographically. Lexicographical sorting is a fancy name for the intuitive dictionary-like sorting of text ('a' < 'b', 'cat' < 'dog', etc...). Lua implements this by default for string comparison.function CompareGui(a, b) return a.Name < b.Name end
myListLayout.SetCustomSortFunction(CompareGui)
SortOrder
of that list layout object to Custom
, like this:myListLayout.SortOrder = Enum.SortOrder.Custom
Voila! You should have an alphabetically sorted list. You may want to sort on the Text
property of your GuiObjects instead of Name
, though. It's up to you.
I haven't tested this API before, so there might be some quirks to work out, but that's a rough guide to get you started.
your question is quite confusing lol but, i try
local yourtable = { [1] = your.thing.here, [2] = your.thing.here, [3] = your.thing.here, [4] = your.thing.here, [5] = your.thing.here, [6] = your.thing.here, [7] = your.thing.here, [8] = your.thing.here, [9] = your.thing.here, [10] = your.thing.here, [11] = your.thing.here, [12] = your.thing.here, } for i,v in pairs(yourtable) do -- i,v mean index,value print(v) --would print the value(second parameter of the table) e.g your.thing.here print(i) --would print the index(first parameter of the table) e.g 7 end
you can try what you want its not very clear o3o