Sorting a list

Monkey Forums/Monkey Beginners/Sorting a list

Arabia(Posted 2014) [#1]
I'm trying to use the Sort method for a list of Int's and keep coming up with an : Unable to compare items error.

	
Field player1:List<Int> = New List<Int>()

' some code to add items to the list (may contain duplicate values)

player1.Sort(True)


I'm sure I'm missing something simple here.


nikoniko(Posted 2014) [#2]
Use IntList


Arabia(Posted 2014) [#3]
Sorry if this sounds stupid, what do you mean by Use IntList?


dawlane(Posted 2014) [#4]
Read http://www.monkey-x.com/docs/html/Modules_monkey.list_IntList.html
You should also look at the Compare function for Lists etc. http://www.monkey-x.com/docs/html/Modules_monkey.list_List.html#Compare


nikoniko(Posted 2014) [#5]
IntList http://www.monkey-x.com/docs/html/Modules_monkey.list_IntList.html

Compare() is abstract method in List class. You should extend list class to compare (yours) list items or use IntList(), FloatList(), StringList() to build in types.


Arabia(Posted 2014) [#6]
Thank you guys, I didn't quite understand what you were saying. For the benefit of anyone else who runs into this issue, I simply needed to use:

Field deck:IntList = New IntList


instead of the deck:List = New List