-- This is an example Lua code block If you say so
What I am attempting to achieve is sorting a table with multiple values in a certain order.
The Order I am attempting to achieve.
Rarity > Level > Name
So, a “Higher Tier” Rarity would be placed higher than a “Lower Tier” rarity.
In an example, a rare would be higher than a Common.
I then want to sort by level.
So for an example
A common peasant lvl 15 would be placed before a common peasant lvl 7 or a common noob lvl 5
Lastly, I would like to finalize the sorting by alphabetical. So things with the same rarity and lvl would then be prioritized by alphabetical. So a peasant lvl 10 would be behind a noob lvl 10.
Currently, I achieved the rarity and level sorting, but I can’t seem to get the alphabetical search as well.
you can see here at the bottom it goes Dummy > Noob > Dummy >Noob, or in the middle it has the Human behind Peasant
And I for some reason just can’t wrap my head around adding in the last part. I have tried things like.
A.Name:lower() < B.Name:lower()
A.Name < B.Name
Here is how the code is setup Currently
table.sort(Inv, function(A, B)
if A:GetAttribute("Rarity") ~= B:GetAttribute("Rarity") then
return table.find(Rarities, A:GetAttribute("Rarity")) < table.find(Rarities, B:GetAttribute("Rarity"))
elseif A:GetAttribute("Level") > B:GetAttribute("Level") then
return A:GetAttribute("Level") > B:GetAttribute("Level")
else
return A.Name < B.Name
end
end)
The only other solution I could think of was to assign a number to the first letter and attempt to sort like that, but that seems like a lot of extra steps for something that seems to be simple. I just don’t know why I can’t wrap my head around it lol anyway