Sorting a Type

BlitzMax Forums/BlitzMax Beginners Area/Sorting a Type

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.

BlitzMax won't magically guess how you want to sort it. When sorting objects, it relies on the 'Compare' method to be able to give the relative order of 2 objects. You need to define this method.Something like:
Type blahType      'define the class
   Field x, y

    Method Compare%(other:Object)
        Local t:blahType = blahType(other)
        If t = Null Then
           ' Not of the right type, fallback on default comparison
            Return Super.Compare(other)
        Else
            ' OK, let's compare them, first base on x, then y
            Local diff% = x - t.x
           If x = 0 Then
                diff = y - t.y
           EndIf
           Return diff
        EndIf
    End Method
EndType