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:
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.
Use these numbers to assign the LayoutOrder on your frames.
This pictures shows the frames being ordered correctly.