Results 1 to 3 of 3

Thread: Out of range

  1. #1
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default Out of range

    Well, I'm taking the same method MasterKill uses for making multiplayer forms, but I always seem to get Out Of Range errors on the Form.ShowModal line when I click the "Add Player" button.

    Script:

    SCAR Code:
    Program Default;
    {.include SRL\SRL.scar}

    var
      CurrentFP: Integer;
      Form: TForm;
      Edits: Array [0..4] of TEdit;
      CheckBoxes: Array [0..1] of TCheckBox;
      RadioButtons: Array [0..1] of TRadioButton;
      Buttons: Array [0..7] of TButton;
      RunScript: Boolean;
      ComboBoxes: Array [0..1] of TComboBox;
      PlayerList: TListBox;


    Procedure FillPlayerList;
    Var
      i: Integer;
    Begin
      With PlayerList do
      Begin
        Clear;
        For i := 0 to HowManyPlayers - 0 do
          With Items do
            Add(Players[i].Name);
      end;
    end;

    Procedure ResetFields;
    Var
      i: Integer;
    Begin
      For i := 0 to 4 do
        With Edits[i] do
          Text := '';
      With CheckBoxes[1] do
        Checked := False;
      With ComboBoxes[1] do
        Text := 'True';
    end;

    Procedure ItemClicked(Sender: TObject);
    Var
    i: Integer;
    Begin
      Case Sender of
        PlayerList: Begin
                    end;
        Buttons[0]: WriteLN('1');
        Buttons[1]: WriteLN('2');
        Buttons[2]: Begin
                      Try
                        Players[CurrentFP].Name := Edits[0].Text;
                        Players[CurrentFP].Pass := Edits[1].Text;
                        Players[CurrentFP].Integers[0] := StrToIntDef(Edits[4].text, 0);
                        If not(ComboBoxes[0].Text = 'Select Log Type') then
                          Players[CurrentFP].Strings[0] := ComboBoxes[0].Text
                        Else
                        Begin
                          ShowMessage('Player form incomplete, please fill in all areas');
                          Exit;
                        end;
                      Except
                        ShowMessage('Player form incomplete, please fill in all areas');
                        //WriteLN(ExceptionToString(ExceptionType, ExceptionParam));
                        Exit;
                      end;
                      Players[CurrentFP].Active := StrToBool(ComboBoxes[1].Text);
                      Players[CurrentFP].Nick := Edits[2].Text;
                      Players[CurrentFP].BoxRewards := srl_Explode(Edits[3].text, ',');
                      For i := 0 to High(Players) do
                      Begin
                        SetArrayLength(Players[i].Integers, 1);
                        SetArrayLength(Players[i].Strings, 1);
                      end;
                      CurrentFP := CurrentFP + 1;
                      HowManyPlayers := HowManyPlayers + 1;
                      NumberOfPlayers(HowManyPlayers);
                      FillPlayerList;
                      ResetFields;
                    end;
        Buttons[3]: WriteLN('4');
        Buttons[4]: WriteLN('5');
        Buttons[5]: Begin
                      Form.ModalResult:= mrOk;
                    end;
        Buttons[6]: WriteLN('7');
      end;
    end;

    procedure InitForm;
    Var
      i: Integer;
      Labels: Array [0..5] of TLabel;
      LabelNames: Array [0..4] of Array of String;
    begin
      LabelNames[0] := ['Username:', 'Password:', 'NickName:', 'Box Rewards:', 'Loads:', 'Active:'];
      LabelNames[1] := ['Fletch', 'String'];
      LabelNames[2] := ['Longbow', 'Shortbow'];
      LabelNames[3] := ['Normal', 'Oak', 'Willow', 'Maple', 'Yew', 'Magic'];
      LabelNames[4] := ['Load player list', 'Save player list', 'Add player', 'Delete player', 'Start script', 'Exit without saving', 'Save and Exit', 'Clear Player List'];
      Form := CreateForm;
      With Form do
      begin
        Left := 300;
        Top := 100;
        Width := 500;
        Height := 500;
        Caption := 'Cut Me Up!';
        Color := clWhite;
        PixelsPerInch := 96;
        With Font do
        Begin
          Color := clWindowText;
          Name := 'Comic Sans MS';
        end;
      end;
      For i := 0 to 3 do
      Begin
        Edits[i] := TEdit.Create(Form);
        With Edits[i] do
        Begin
          Parent := Form;
          Top := 100 + (30 * (i + 1));
          Left := 110;
          Width := 200;
          Height := 20;
        end;
      end;
      With Edits[1] do
        PasswordChar := '*';
      Edits[4] := TEdit.Create(Form);
      With Edits[4] do
      Begin
        Parent := Form;
        Top := 160;
        Left := 360;
        Width := 70;
        Height := 20;
      end;
      For i := 0 to 3 do
      Begin
        Labels[i] := TLabel.Create(Form);
        With Labels[i] do
        Begin
          Parent := Form;
          Top := 100 + (30 * (i + 1));
          Left := 20;
          Caption := LabelNames[0][i];
          With Font do
          Begin
            Color := clBlack;
            Name := 'Comic Sans MS';
            Size := 10;
          end;
        end;
      end;
      For i := 4 to 5 do
      Begin
        Labels[i] := TLabel.Create(Form);
        With Labels[i] do
        Begin
          Parent := Form;
          Top := -110 + (60 * i);
          Left := 372;
          Caption := LabelNames[0][i];
          With Font do
          Begin
            Color := clBlack;
            Name := 'Comic Sans MS';
            Size := 10;
          end;
        end;
      end;
      ComboBoxes[1] := TComboBox.Create(Form);
      With ComboBoxes[1] do
      Begin
        Parent := Form;
        Top := 220;
        Left := 360;
        Width := 70;
        Height := 20;
        Text := 'True';
        With Items do
        Begin
          Add('True');
          Add('False');
        end;
      end;
      For i := 0 to 1 do
      Begin
        CheckBoxes[i] := TCheckBox.Create(Form);
        With Checkboxes[i] do
        Begin
          Parent := Form;
          Top := 240 + (25 * (i + 1));
          Left := 30;
          Width := 80;
          Height := 15;
          Caption := LabelNames[1][i];
          If i = 0 then
            Checked := True;
        end;
      end;
      For i := 0 to 1 do
      Begin
        RadioButtons[i] := TRadioButton.Create(Form);
        With RadioButtons[i] do
        Begin
          Parent := Form;
          Top := 240 + (25 * (i + 1));
          Left := 200;
          Width := 80;
          Height := 15;
          Caption := LabelNames[2][i];
          If i = 0 then
            Checked := True;
        end;
      end;
      ComboBoxes[0] := TComboBox.Create(Form);
      With ComboBoxes[0] do
      Begin
        Parent := Form;
        Top := 272;
        Left := 340;
        Width := 110;
        Height := 20;
        Text := 'Select Log Type';
        For i := 0 to High(LabelNames[3]) do
          With Items do
            Add(LabelNames[3][i]);
      end;
      PlayerList := TListBox.Create(Form);
      With PlayerList do
      Begin
        Parent := Form;
        Top := 330;
        Left := 20;
        Width := 150;
        Height := 120;
        OnClick := @ItemClicked;
      end;
      For i := 0 to 7 do
      Begin
        Buttons[i] := TButton.Create(Form);
        With Buttons[i] do
        Begin
          Parent := Form;
          Height := 25;
          Width := 120;
          OnClick := @ItemClicked;
          Caption := LabelNames[4][i];
          If (i mod 2) = 0 then
          Begin
            Left := 200;
            Top := 310 + (i * 20);
          end else
          Begin
            Left := 330;
            Top := 310 + ((i - 1) * 20);
          end;
        end;
      end;
    end;

    procedure SafeInitForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm', v);
    end;

    procedure ShowFormModal;
    begin
      Form.ShowModal;
    end;

    procedure SafeShowFormModal;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowFormModal', v);
    end;

    Procedure DoForm;
    begin
      CurrentFP := 0;
      HowManyPlayers := CurrentFP + 1;
      NumberOfPlayers(HowManyPlayers);
      SafeInitForm;
      SafeShowFormModal;
      If RunScript then
        TerminateScript;
    end;

    begin
      DoForm;
    end.

    I know the form is pretty bad right now, but I haven't got round to doing the style bits.

    Thanks

  2. #2
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Line 23: For i := 0 to HowManyPlayers - 1 do

  3. #3
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Line 23: For i := 0 to HowManyPlayers - 1 do
    Thanks, I'll add to your billions of rep

    I'm not quite sure why I typed - 0...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •