rendered paste bodyalias Sort {
var %c = $lines(Hscore.txt), %i = 1, %1, %2
:sort
var %s = 0
var %i = 1
:loop
%1 = $gettok($read(Hscore.txt,%i),2,61)
var %a = $readn
%2 = $gettok($read(Hscore.txt,$calc(%i + 1)),2,61)
var %b = $readn
if (%1 < %2) {
echo -s Line 1: %a Line 2: %b Cash 1: %1 Cash 2: %2
%1 = $read(Hscore.txt,%i)
%2 = $read(Hscore.txt,$calc(%i + 1))
write -dl [ $+ [ %i ] ] Hscore.txt
write -il [ $+ [ %i ] ] Hscore.txt %2
write -dl [ $+ [ $calc(%i + 1) ] ] Hscore.txt
write -il [ $+ [ $calc(%i + 1) ] ] Hscore.txt %1
%s = %i
}
inc %i
if (%i < %c) goto loop
else %i = 1
if (%s != 0) goto sort
echo -s Sorted: $lines(Hscore.txt) players.
}