Results 1 to 6 of 6

Thread: Need help in forms!

  1. #1
    Join Date
    Jun 2006
    Location
    USA
    Posts
    1,828
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default Need help in forms!

    I need help in making forms. I tried to do easy examples, but when i run the script it says:
    SCAR Code:
    Runtime Error] : Exception: Cannot make a visible window modal in line -- in script
    Anybody knows what did I do wrong? Can somebody do me example how to make form where you can put your player name and then it reads it from form to here:
    SCAR Code:
    procedure DeclarePlayers;
    begin
    Players[0].Name :=(The name from form);
    end;
    Please can somebody help me.

  2. #2
    Join Date
    Feb 2006
    Location
    London, England
    Posts
    2,045
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    (The name from form).Visible := True
    to
    (The name from form).Visible := False;
    SRL Wiki | SRL Rules | SRL Stats
    Ultimate SCAR Scripting Tutorial | Starblaster100's Auth System | Join the official SRL IRC now!


    Help Keep SRL Alive! Please disable Advert Blockers on SRL! Help Keep SRL Alive!


  3. #3
    Join Date
    Jun 2006
    Location
    USA
    Posts
    1,828
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol. Thanks very much!!! That helped me alot!
    Can you tell me how can i make my "OK" button to Close form window?
    Here's my code:
    SCAR Code:
    program New;
    {.include srl/srl.scar}
    var
      frmDesign : TForm;
      Name : TEdit;
      Ok : TButton;
     
    procedure InitForm;
    begin
    frmDesign := CreateForm;
    frmDesign.Left := 250;
    frmDesign.Top := 114;
    frmDesign.Width := 158;
    frmDesign.Height := 190;
    frmDesign.Caption := 'frmDesign';
    frmDesign.Color := clBtnFace;
    frmDesign.Font.Color := clWindowText;
    frmDesign.Font.Height := -14;
    frmDesign.Font.Name := 'MS Sans Serif';
    frmDesign.Font.Style := [];
    frmDesign.Visible := false;
    frmDesign.PixelsPerInch := 120;
    Name := TEdit.Create(frmDesign);
    Name.Parent := frmDesign;
    Name.Left := 10;
    Name.Top := 35;
    Name.Width := 121;
    Name.Height := 24;
    Name.Hint := 'Player name';
    Name.TabOrder := 8;
    Name.Text := 'Name';
    Ok := TButton.Create(frmDesign);
    Ok.Parent := frmDesign;
    Ok.Left := 39;
    Ok.Top := 86;
    Ok.Width := 46;
    Ok.Height := 27;
    Ok.Caption := 'Ok';
    Ok.TabOrder := 9;
    end;

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

    procedure ShowFormModal;
    begin
      frmDesign.ShowModal;
    end;

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

     procedure Declareplayers;
      begin
      HowManyPlayers:=1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer:=0;
      Players[0].Name:=Name.Text
      end;

    procedure WriteName;
    begin
    writeln(Players[0].Name)
    end;

    begin
      SafeInitForm;
      SafeShowFormModal;
      setupsrl;
      DeclarePlayers;
      WriteName;
    end.

    EDIT:
    I found out it myself.

  4. #4
    Join Date
    Oct 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This is a crappy way of doing things, but i use it for beta scripting purposes . Readln FTW!

  5. #5
    Join Date
    Feb 2006
    Location
    London, England
    Posts
    2,045
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    Get ready for a long post :

    To make a button, you need to make a special type of Procedure called a sender. Its basically a procedure which works on a form.

    so:

    PHP Code:
    Procedure ClickTheOKButton(senderTObject);
    Begin
      
    (The name from form).Caption := FrmAth.Caption+'.';  //This adds a 'Period' to the end of the title.  Its so if something goes wrong, you can see what, but most of the time its useless.
      
    (The name from form).ModalResult := mrOk;  //Tells the script that everything is A-OK and we should carry on.
    end
    Now to the main form procedure:
    PHP Code:
    Ok := TButton.Create(frmDesign);
    Ok.Parent := frmDesign;
    Ok.Left := 39;
    Ok.Top := 86;
    Ok.Width := 46;
    Ok.Height := 27;
    Ok.Caption := 'Ok';
    Ok.TabOrder := 9;
    OK.OnClick := @ClickTheOKButton//Ive added this line.  this says when the button is clicked, calle the ClickTheOKButton procedure. 
    And thats a button done.

    The only bad thing about it though is that if you were to press the X button on the form to close it down the script would still continue. So here is what i added. A global Variable called ScriptStart:

    PHP Code:
    Var
      
    ScriptStartBoolean;

    Procedure ClickTheOKButton(senderTObject);
    Begin
      
    (The name from form).Caption := FrmAth.Caption+'.';
      (
    The name from form).ModalResult := mrOk;
      
    ScriptStart := True;
    end;

    Procedure InitForm;
    Begin
    //The usual Stuff here
    end;

    //3 boring procedures here all forms need, which you already have

    //mainLoop:
    Begin
      SafeInitForm
    ;
      
    SafeShowFormModal;
      If(
    ScriptStart False)then
        TerminateScript
    ;
      
    setupsrl;
      
    DeclarePlayers;
      
    WriteName;
    end
    Now this means that ScriptStart will only be set to true if that button is clicked. If not, it will be false and hence the script will terminate

    Thats all

    Good luck scripting!
    SRL Wiki | SRL Rules | SRL Stats
    Ultimate SCAR Scripting Tutorial | Starblaster100's Auth System | Join the official SRL IRC now!


    Help Keep SRL Alive! Please disable Advert Blockers on SRL! Help Keep SRL Alive!


  6. #6
    Join Date
    Jun 2006
    Location
    USA
    Posts
    1,828
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    This is great! Thank you for helping with this!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Forms
    By marre in forum OSR Help
    Replies: 2
    Last Post: 12-19-2007, 07:53 PM
  2. Need help with forms!
    By Da Der Der in forum OSR Help
    Replies: 2
    Last Post: 01-14-2007, 07:13 PM

Posting Permissions

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