I'm developing a simple friend system and want to sort the friendData with some rules.
I compared two friends' status , level and offline-Time.
PS:A friend has 3 status.(Online = 3,Busy = 2,Offline = 1).
Here's my code.
local function compare(friend1,friend2)
local iScore1 = 0
local iScore2 = 0
if friend1["eStatus"] > friend2["eStatus"] then
iScore1 = iScore1 + 1
end
if friend1["iLevel"] > friend2["iLevel"] then
iScore1 = iScore1 + 1
end
if friend1["iOfflineTime"] < friend2["iOfflineTime"] then
iScore1 = iScore1 + 1
end
return iScore1 > iScore2
end
table.sort(FriendData,compare)
It works when I add several friends.But when I get more friends,It throws exception "invalid order function for sorting". Can someone please tell me how to fix it? :)