Is SORTARRAY with user-defined compare routine working okay ?

Previous topic - Next topic

MrTAToad

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.

Kitty Hello

Return value of that function must not be "%".

MrTAToad

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.