Why IS this code WORKING?

BlitzMax Forums/BlitzMax Beginners Area/Why IS this code WORKING?

This question may seem odd but my code now works via tinkering around. It actually sorts my highscore objects by their score values WITHOUT me telling them to. Why is this? It's great that it works but things like this often have very iffy results...

' demo of sorting highscore elements

Strict
Graphics 640,480
SeedRnd MilliSecs()
' make some data objects
Global scores:TList = New TList
Type score_data
	Field score%,name$, level%
	
	Function create(score%,name$,level%)
		' psuedo rqandom for nwo
		Local temp:score_data=New score_data
		temp.name=name
		temp.score=score
		temp.level=level
		ListAddLast(scores,temp)
	End Function
	
	Method Compare(otherObject:Object)
		Local m:score_data = score_data(otherObject)
		If Not m Return 1
		Return score - m.score 
	End Method

	

End Type

' make 20 score datas
For Local i=0 To 10
	score_data.create(Rand(0,1000000),String(Chr(Rand(65,90)))+String(Chr(Rand(65,90)))+String(Chr(Rand(65,90))),Rand(1,7))
Next
SortList(scores,1)
ReverseList(scores)
' pring them then sort them
Print"/\/\/\/\/\/\/\/\/\/\/\/\/\/"
For Local i:score_data=EachIn(scores)
	Print(i.score+" "+i.name+" "+i.level)
Next


' now display the characters 
While Not KeyDown(key_escape)
Cls
	SetColor 255,255,255
	DrawText("press escape key to quit",0,0)
	Local counter=0
	For Local i:score_data=EachIn(scores)
	counter:+1
	DrawText("Score: "+i.score+" "+i.name+ " "+i.level,32,32+(counter*14))
	Next
Flip
Wend


I see a Sortlist in there?

Your Method Compare is screwy though. Just suppose to return 1 for Yes and -1 for No.

Method Compare(otherObject:Object)
If otherObject.score>score Return 1
Return -1
End Method

@Ryan Burnside:Just in case your question is how sortlist knows how to sort your list:

The method compare is suposed to be implemented for 'sortable' types. In your compare method you're telling how to sort your scores, as the comparison is being made by the score field. Change the score field comparison by a "player" field comparison, and you'll get the socres sorted by player's name. Isn't it great?

Thanks you for all your help.