custom sorting of arrays in javascript.

this isn’t working:

First, I get an array of the user’s facebook friends. I get an array of “drUser” objects. each object has a string called “platformName” that I want to use to sort the drUser objects in the array.

			yield drClient.User.FetchAllFriends();
			yield drClient.User.FetchAppFriends();
			
			loadMyFriends  	= true;
			appFriends  		= drClient.User.localUser.appFriends;
			friends 				= drClient.User.localUser.socialNetworkFriends;
			
			appFriends.Sort(SortFriendsByName);
			friends.Sort(SortFriendsByName);

the sort function i’m using is this:

function SortFriendsByName(a, b)
{	
	var tempArray : Array = new Array(a.platformName, b.platformName);
	
	tempArray.Sort();
	
	if(a.platformName == tempArray[0])
		return -1;
	else
		return 0;
}

It’s not working. unity tells me the following:

Assets/Scripts/Singleton/FriendManager.js(36,40): BCE0017: The best overload for the method ‘Array.Sort()’ is not compatible with the argument list ‘(callable(Object, Object) as int)’.

any help would be fantastic.

Thanks folks.

What type is platformName, that error suggests that you are trying to sort some Objects and unity doesn’t know how to order them.

they are both strings…

Can i even compare strings in unity in a way that isn’t == ?

edit: just found out that there’s a string.Compare(otherstring) in the .net framework that works fine.

i’ll try that tonight when i get back to my codage.