Custom Compare() method causes problems...

BlitzMax Forums/BlitzMax Programming/Custom Compare() method causes problems...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Seems to work fine here :

Your code with some test stuff added...
Type TElement
	Global glElements:TList

	Field piZ% = 0			'used for layering the sprites (higher Z-values are on top of lower Z-values)

	Method New() 
		If Not glElements Then glElements = CreateList() 
		glElements.AddLast(Self) 
	End Method
	
	Method Kill() 
'none of these functions work because they all use Compare() to find the proper link :(
'		RemoveLink(ListFindLink(glElements, Self)) 
'		ListRemove(glElements, Self)
		glElements.Remove(Self) 
	End Method
		
   Function UpdateAll() 
      For Local e:TElement = EachIn glElements
'         e.update() 
      Next
   End Function
	
'	You must actively call this function in order to get all sprites sorted by Z-value (performance issue)
'	optional argment 'bAscending' can be used to sort the sprites reversed (highest Z-value first)  
	Function SortZ(bAscending% = True) 
		glElements.Sort(bAscending) 
	End Function
		
'	This method is used for sorting the glSprites list in Z-order (ascending)
	Method Compare%(OtherObj:Object)
		Local e:TElement = TElement(OtherObj) 
		If Not e Return Null
		Return piZ - e.piZ
	End Method


'	Abstract Methods
	'Method Update() Abstract
	'Method Draw() Abstract

'	----------------
End Type

Local e:TElement = New TElement
e.piZ = 3

e = New TElement
e.piZ = 1


e = New TElement
e.piZ = 5

DebugLog "Ascending..."
TElement.SortZ()

For e = EachIn TElement.glElements
	DebugLog e.piZ
Next

DebugLog "Descending..."
TElement.SortZ(False)

For e = EachIn TElement.glElements
	DebugLog e.piZ
Next