Ok, I'm building a script that SHOULD return the levels and names of the characters around me, then sort them into a list by levels.

Only problem? Every time I tell sort the names, it crashes.

Here's the script, any help is appreciated.

SCAR Code:
program New;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

var
  // ItemForm variables.
  EndItemForm : Boolean;
  ItemIdform : TForm;
  Label1 : TLabel;
  Button1, Button2, Button3 : TButton;
  Memo1, Memo2 : TMemo;
  Items, Npcs : TObject;
  Page : Integer;
  People : Array of TPlayer;

// When the form is closed, this code will be executed.
procedure ItemFormOnClose(Sender : TObject; var Action : TCloseAction);
begin
  if (not(ItemIdform.ModalResult = 1)) then
    EndItemForm := True;
end;

Function Highest(Numbers : Array of TPlayer) : Integer;
Var
  I, P : Integer;
Begin
  P := 0;
  For I := 0 To High(Numbers) Do
  Begin
    Wait(10);
    If Numbers[I].level > P then
      P := I;
  End;
  Result := P;
End;

Function Lowest(Numbers : Array of TPlayer) : Integer;
Var
  I, P : Integer;
Begin
  P := 138;
  For I := 0 To High(Numbers) Do
  Begin
    If Numbers[I].level < P then
      P := I;
  End;
  Result := P;
End;

Procedure UpdateForm(Sender : TObject);
Var
  I, H : Integer;
Begin
  People := GetPlayers;
  For I := 0 To High(People) Do
  Begin
    Wait(10);
    If Memo1.Visible then
    Begin
      H := Highest(People);
      Wait(1);
      With Memo1.Lines Do
        Add(People[H].name + ' - ' + IntToStr(People[H].level));
    End else
    Begin
      H := Lowest(People);
      Wait(1);
      With Memo2.Lines Do
        Add(People[H].name + ' - ' + IntToStr(People[H].level));
    End;
  End;
End;

procedure Changing(Sender: TObject);
begin
  If Page = 1 Then
  Begin
    Memo2.Visible := True;
    Memo1.Visible := False;
  End else
  Begin
    Memo2.Visible := False;
    Memo1.Visible := True;
  End;
end;

Procedure Changing1(Sender: TObject);
Begin
  Dec(Page);
  If Page <> (0 or 1) Then
    Page := 0;
  Changing(Items);
End;

Procedure Changing2(Sender: TObject);
Begin
  Inc(Page);
  If Page <> (0 or 1) Then
    Page := 0;
  Changing(Npcs);
End;

// This form was parsed using: DFM Form Parser v.25 by Ron.
procedure ItemForm;
var
  TimeItemForm : Integer;
begin
  TimeItemForm := GetSystemTime;
  ItemIdform := CreateForm;
  with ItemIdform do
  begin
    OnClose := @ItemFormOnClose;
    Position := poScreenCenter;
    BorderStyle := bsSingle;
    BorderIcons := [biMinimize,biSystemMenu];
    ClientWidth := 211;
    ClientHeight := 258;
    Caption := 'Combat Sorter';
    Color := clBtnFace;
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'MS Sans Serif';
    Font.Style := [];
    PixelsPerInch := 96;
  end;
  Label1 := TLabel.Create(ItemIdform);
  with Label1 do
  begin
    Parent := ItemIdform;
    Left := 40;
    Top := 0;
    Width := 129;
    Height := 12;
    Caption := 'Combat level to sort by?';
  end;
  Button1 := TButton.Create(ItemIdform);
  with Button1 do
  begin
    Parent := ItemIdform;
    Left := 75;
    Top := 16;
    Width := 65;
    Height := 25;
    Caption := 'Update';
    TabOrder := 9;
    OnClick := @UpdateForm;
  end;
  Button2 := TButton.Create(ItemIdform);
  with Button2 do
  begin
    Parent := ItemIdform;
    Left := 10;
    Top := 16;
    Width := 65;
    Height := 25;
    Caption := 'Highest';
    TabOrder := 9;
    OnClick := @Changing1;
  end;
  Button3 := TButton.Create(ItemIdform);
  with Button3 do
  begin
    Parent := ItemIdform;
    Left := 140;
    Top := 16;
    Width := 65;
    Height := 25;
    Caption := 'Lowest';
    TabOrder := 10;
    OnClick := @Changing2;
  end;
  Memo1 := TMemo.Create(ItemIdform);
  with Memo1 do
  begin
    Parent := ItemIdform;
    Left := 8;
    Top := 48;
    Width := 193;
    Height := 209;
    TabOrder := 11;
  end;
  Memo2 := TMemo.Create(ItemIdform);
  with Memo2 do
  begin
    Parent := ItemIdform;
    Left := 8;
    Top := 48;
    Width := 193;
    Height := 209;
    TabOrder := 12;
    Visible := False;
  end;
  WriteLn('ItemForm compiled in ' + IntToStr(GetSystemTime - TimeItemForm) + ' milliseconds!');
end;

procedure SafeItemForm;
var
  V : TVariantArray;
begin
  SetArrayLength(V, 0);
  ThreadSafeCall('ItemForm', V);
end;

procedure ShowItemFormModal;
begin
  ItemIdform.ShowModal;
end;

procedure SafeShowItemFormModal;
var
  V : TVariantArray;
begin
  SetArrayLength(V, 0);
  ThreadSafeCall('ShowItemFormModal', V);
end;

procedure MainItemForm;
begin
  try
    SafeItemForm;
    SafeShowItemFormModal;
  finally
    FreeForm(ItemIdform);
  except
    WriteLn('An error seems to have occurred in: ItemForm');
  end;
end;

procedure SetupSmart;
begin
  SmartSetupEx(144, True, true, false);
    while not SmartActive do wait(100);
  SetTargetDC(SmartGetDC);
end;

begin
  SetupSRL;
  SetupSMART;
  ClearDebug;
  GetSelf.WindowState := wsMinimized;
  MainItemForm;
  GetSelf.WindowState := wsNormal;
  if (EndItemForm) then
    TerminateScript;
end.

~Sandstorm
~Sandstorm