Whilst developing mechanics for my upcoming Scrapyard game, I had this interesting thought where, as you salvage materials from wreckage, the parts that make up the trash model gradually shrink to nothingness until, when the Model has no base parts left inside, it gets deleted.
So, to add to this concept, I developed a
The function does this:
function findLongest(part) local s = part.Size -- Get the part's size. local x = s.X local y = s.Y local z = s.Z if x>y and x>z then -- X is longer than Y and Z return "X" elseif y>x and y>z then -- Y is longer than Z and X return "Y" elseif z>x and z>y then -- Z is longer than X and Y return "Z" elseif x==y and y>z then -- Z is shorter than X and Y; X:Y return "XY" elseif y==z and z>x then -- X is shorter than Y and Z; Y:Z return "YZ" elseif z==x and x>y then -- Y is shorter than Z and X; Z:X return "XZ" else -- X == Y == Z return "XYZ" end end
- If all of a part’s sides are not equal to each other, it will return the longest of the sides.
- If two of the sides are equal to each other and longest of them all, it will return these two sides.
- If these two last statements are false, then this means the object is equilateral, so
FindLongestDemo.rbxl (23.5 KB)
This .rbxl file demonstrates the function.
I am not sure if the code is efficient enough with the long
So, I was thinking, “Could I do something else that is better than a long
I am trying to optimize the function by finding a better alternative to a long
if-elseif-else chain; if you have a better method than the chain, please notify me. Otherwise, if the code is fine enough, you could say that too.