Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't my sorting algorithm work properly?

Hi, guys, I got a very basic sorting algorithm here, but it just doesn't seem to work properly for any integer greater than 9. I'll show you: table.sort(all, (function(a, b) if a.Speed > b.Speed then print(a.Speed, b.Speed) return true end end)) returns the following:

4 10 6 4 (x2) 9 4 9 8 8 6 (x3) As you can see it thinks that 4 is larger than 10. Why is that? I seriously cannot think of any reason why this would happen and therefore cannot think of a way to solve it. Help would be greatly appreciated since this apparent bug is stopping me from continuing.

The table all contains the following integers: 10, 9, 8, 8, 6, 6, 4, 4 The Speed is saved in StringValues and then moved into a table which is then saved in a metatable(all).

1 answer

Okay, I solved it. The Speed values were saved in StringValue objects and since I didn't use tonumber() on them the 10 was apparently interpreted as binary, therefore making it a 2.

This discussion is preserved as it was. New answers, comments, and votes are closed.