Quote: "A reverse sort command for arrays, i.e. an easy way to sort descending. "
Here is a function to do just that. You can call it to sort a string array by ascending or descending order. Uses simple bubble sort algorithm.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=.
// UTILITY FUNCTION: Sort String Array (0 = Ascending, 1 = Descending)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='
Function SortStringArray(ar ref as string[], order As Integer)
// Ascending Order
If order = 0
ar.sort()
ExitFunction
Endif
// Descending Order
temp As String
for i = ar.length to 0 Step -1
for j = 1 to i
temp = ar[j-1]
ar[j-1] = ar[j]
ar[j] = temp
next j
next i
EndFunction
And here is a full example using names:
// Project: ArraySort
// Created: 2018-03-22
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "ArraySort" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
Global Username As String[4]
Username[0] = "Susan"
Username[1] = "Fred"
Username[2] = "William"
Username[3] = "Paul"
Username[4] = "Anne"
Username.sort()
sortOrder = 0
do
Print("Press Pointer To Reverse Sort Order") : Print("")
If GetPointerPressed() Then SortString(Username, 1 - sortOrder)
For i = 0 To Username.length
Print(Username[i])
Next i
Sync()
loop
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=.
// UTILITY FUNCTION: Sort String Array (0 = Ascending, 1 = Descending)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='
Function SortStringArray(ar ref as string[], order As Integer)
// Ascending Order
If order = 0
ar.sort()
ExitFunction
Endif
// Descending Order
temp As String
for i = ar.length to 0 Step -1
for j = 1 to i
temp = ar[j-1]
ar[j-1] = ar[j]
ar[j] = temp
next j
next i
EndFunction
Easily adaptable for integers as well.