GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2009-Mar-20

Title: Is SORTARRAY with user-defined compare routine working okay ?
Post by: MrTAToad on 2009-Mar-20
I'm using the following :

Code (glbasic) Select
SORTARRAY localHiscores[],ADDRESSOF(sortRoutine_Local)

with the following compare routine :

Code (glbasic) Select
FUNCTION sortRoutine_Local%:a AS tLocalHiscores,b AS tLocalHiscores
IF a.score%>b.score%
RETURN -1
ELSE
IF a.score%<b.score%
RETURN 1
ELSE
RETURN 0
ENDIF
ENDIF
ENDFUNCTION


to sort an array of the following TYPE :

Code (glbasic) Select
TYPE tLocalHiscores
name$
score%
grade$
ENDTYPE


But for some reason the program crashes.
Title: Re: Is SORTARRAY with user-defined compare routine working okay ?
Post by: Kitty Hello on 2009-Mar-20
Return value of that function must not be "%".
Title: Re: Is SORTARRAY with user-defined compare routine working okay ?
Post by: MrTAToad on 2009-Mar-21
Yes, that's solved it - thanks!

Might need to change the help file there as "SORTARRAY array[], cmp%" implies the comparison function returns an integer.