Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my sorting algorithm work properly?

Asked by
Wutras 294 Moderation Voter
5 years ago

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

Log in to vote
0
Answered by
Wutras 294 Moderation Voter
5 years ago

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.

Ad

Answer this question