How can I get visual order of an item inside of UIListLayout thing?


Hello! I’m working on what is this, item select ui? (can’t describe better with my English)
These items are sorted by its prices.

I want to get each item ui’s order, so that you can select item by scrolling it with some keys like this:

If anyone has any idea, better way to do this, or feedback for this, please tell me. Thank you!

Like this ? (this does making TextLabel’s text (which is inside of this item UI) to item UI of LayoutOrder’s number)

local function getvisualorder()
for i,v in YourUIListLayout:GetChildren() do
v.TextLabel=tostring(v.LayoutOrder)
end
end

edited

You can use the LayoutOrder property inside each frame in the ScrollingFrame

I know there’s LayoutOrder property, I’ve set it to its prices already

What I want to know is the “visual” order of each item UI.

I didnt explain this clearly, sorry!!

You make frame which is not inside of UIListLayout but in GUI which items are in

in this way you need make your own custom select logic script for it

the keys like ← ^- -^ → (get their KeyCodes) should be used for this when gui is presented

position the frame same like to item UI’s position and Size (this could just setting same size as item)

That’s smart.
But I’d recommend setting LayoutOrder to integer value because if you prices contain fractions Roblox will round them and order of such items will become unpredictable.
So you sort the prices and set LayoutOrder according to price index.
You can use the index as an item’s index in the list later.

As an example:

--!strict

local prices : { number } = { 2.5, 4.5, 0.1, 10, 1 }

local function sort_prices(prices : { number })
	table.sort(prices, function(a, b)
		return a < b
	end)
end

sort_prices(prices)
print(prices)

local function find_price_index(price : number) : number?
	return table.find(prices, price)
end

local price_index = find_price_index(4.5)
print("price_index", price_index)
1 Like

What I want to implement is just like this:

I just wrote a code for this, using table.sort as you said. But didnt use table.find
And… it works

local Prices = {}
local Items = {}

-- Making Prices dictionary and Item array for sorting
for i, item: Model in ItemsFolder:GetChildren() do
	Prices[item] = item:GetAttribute("Price")
	Items[i] = item
end

-- Sorting items by their prices
table.sort(Items, function(a, b)
	return Prices[a] < Prices[b]
end)

-- Making ui with this
for i, model: Model in Models do
	-- make button
end

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.