LayoutOrder with decimals?

I’m working on an inventory system for my game, and it includes sort options such as “worst to best” and “best to worst”. How I am deciding what is considered “worse” or “better” is through a number which can include a decimal. LayoutOrder cannot use decimals.

How would I overcome this?

Here’s my code:

for _,v in pairs(scrollingframe:GetChildren()) do
	if v:IsA("Frame") then
		if v.Visible == true then 
			local mult = shopData[v.Name].Multiplier -- finds out how much its multiplier is
			v.LayoutOrder = mult -- changes it based on the multiplier (multiplier can be a decimal, which is where the problem is)
		end
	end
end

To achieve this, you want to get rid of the decimal numbers.
To do this, find the maximum number of decimal places on each of your values.

For example:
Screen Shot 2022-01-25 at 10.48.07
The maximum amount of decimal places in all of these numbers is 3.

Multiple each of these numbers by 10^max (in this case, 10^3 = 1000).
This will remove the decimal places while still keeping the numbers in the right order.

Screen Shot 2022-01-25 at 10.51.01

Use these numbers to assign the LayoutOrder on your frames.

This pictures shows the frames being ordered correctly.

1 Like

If you have an array of options, then you can sort them using table.sort and then just use their index in the array as their LayoutOrder. E.g.

for i, option in ipairs(sortedOptions)
    option.GuiObject.LayoutOrder = i
end
1 Like

Sorry for the late response, what you and @ThanksRoBama said works, thank you!

1 Like