Page 1 of 3 123 LastLast
Results 1 to 25 of 54

Thread: How to add the SRL Player Form to your script

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default How to add the SRL Player Form to your script

    How to add the SRL Player Form to your script




    Introduction


    Hello! I am going to teach you how to add the new SRL player form (SPF) to any script. The SPF is a very customizable user interface that helps script users setup your script. You can have as many or as few player settings as you wish, as well has some other optional properties. I highly recommend adding the SPF to all your scripts - it's simple and makes setting up your script much easier for users. Please read this guide carefullly; it may be confusing.

    This guide assumes you have a decent knowledge of arrays and custom records.

    Features


    As stated above, there is a lot of room for customization. If you'd like a feature added, please suggest it here.

    Features:

    • Automatically loads all user's player files into the "Player File" combo box.
    • Automatically loads a user's previous settings.
    • Scripters can have as many TEdits, TComboBoxes, and TCheckBoxes as they wish.
    • Scripters have the option to set default values for each of the above components.
    • The PlayerForm variable has several attributes that can be customized by the scripter.


    Added SPF to a script


    The SPF can be added to any script in a few easy steps:

    1. Include the Simba file in your script.
    2. Create the SPF init() procedure.
    3. Create the modified decalarePlayers() procedure.
    4. Debug the results (optional)!
    5. Call runPlayerForm() in your mainloop.


    Including it in your script

    Very simple step, just add the following to the top of your script:
    Simba Code:
    program new;
    {$DEFINE SMART}
    {$i srl-6/srl.simba}
    {$i srl-6/lib/misc/srlplayerform.simba} // include the file AFTER srl.simba

    Create the SPF init() procedure

    This is the procedure that declares the SPF settings. In this procedure, you're modifying the "playerForm" variable to your liking. Here's an example procedure explained:

    Simba Code:
    // initiates the SRL player form (you aren't restricted to the procedure name; it can be whatever you want)
    procedure initPlayerForm();
    begin
      with playerForm do
      begin
        name := 'SRL Player Form ~ Test'; // the title of the SPF, usually the name of your script
        scriptHelpThread := '';           // a link to a help thread, if set to '' will link to my setup guide

        editBoxLabels := ['Minutes to run', 'Logs to Chop', 'Minutes before breaking'];     // edit boxes are created for each array element
        editBoxDefaults := ['0', '0', '0'];                                                 // optional default values for each edit box; array length must equal editBoxLabel length

        // optional hints for each edit box; hints are shown when the user holds the mouse over the component
        editBoxHints := ['How long to run (in minutes)?', 'How many logs do you want to chop?', 'Run for this amount of time (in minutes) before breaking.'];

        checkBoxLabels := ['Hatchet Equipped', 'Save SRL log', 'Draw on SMART']; // same as editBoxLabels but for check boxes
        checkBoxDefaults := ['True', 'True', 'False'];
        checkBoxHints := ['Is your hatchet equipped?', 'Do you want to save SRL debug to a log file (recommended)?', 'Do you want do draw some debug information on SMART?'];

        comboBoxLabels := ['Tree Type'];                                                    // same as editBoxLabels but for combo boxes (drop down boxes)
        comboBoxDefaults := ['Willow'];
        comboBoxHints := ['Choose the type of tree you want to chop.'];

        // this needs to be done for every element in the comboBoxLabels array
        setLength(comboBoxItems, length(comboBoxLabels));
        comboBoxItems[0] := ['Normal', 'Oak', 'Willow', 'Maple', 'Yew', 'Magic'];           // all the options available for the first combo box
      end;
    end;
    Once the SPF has run, it will set an array of settings (TStringArray) for each player. The order goes by the UI components declared in the above procedure. For example, the "Minutes to run" setting is element 0, "Minutes before breaking" is element 2, and "Tree Type" is element 6. You want to make sure you use these correctly in the modified declarePlayers() procedure.


    Create the modified declarePlayers() procedure

    This procedure is essential, and I highly recommend debugging player information when you think you're finished. This is the procedure that sets all player information based on an array from the SPF. You don't want to accidentally set a player setting to the wrong data. The player's settings are stored in the "playerForm.players[i].settings" variable.

    The key to this procedure is properly accessing the player's settings that were set by the SPF. Each player will have an array of settings associated with them that were set in the SPF. These settings are all in strings, so they need to be converted when you set different typed attributes. Here's an example explained:

    Simba Code:
    // again, not restricted to the procedure name, although it's recommended
    procedure declarePlayers();
    var
      i: integer;
    begin
      players.setup(playerForm.players); // load the SPF players from the SRL Player Manager
      currentPlayer := 0;                                           // player to use first

      // set player attributes based on the settings from the form
      for i := 0 to high(players) do
        with players[i] do
        begin
          // convert the integers
          integers[0] := strToInt(playerForm.players[i].settings[0]);
          integers[1] := strToInt(playerForm.players[i].settings[1]);
          integers[2] := strToInt(playerForm.players[i].settings[2]);

          // booleans
          booleans[0] := strToBool(playerForm.players[i].settings[3]);
          booleans[1] := strToBool(playerForm.players[i].settings[4]);
          booleans[2] := strToBool(playerForm.players[i].settings[5]);

          // strings
          strings[0] := playerForm.players[i].settings[6];

          // any other data types you've decided to use
        end;
    end;


    Debug the results (optional)

    Although optional, it is highly recommended. This ensures that everything was properly set in your modified declarePlayers() procedure. Here's an example debug procedure for the above SPF:

    Simba Code:
    procedure debugSPFSettings();
    var
      i: integer;
    begin
      writeln('');

      for i := 0 to high(players) do
      begin
        writeln('Minutes to run:          ', players[i].integers[0]);
        writeln('Logs to chop:            ', players[i].integers[1]);
        writeln('Minutes before breaking: ', players[i].integers[2]);
        writeln('Hatchet Equipped:        ', players[i].booleans[0]);
        writeln('Save SRL log:            ', players[i].booleans[1]);
        writeln('Draw on SMART:           ', players[i].booleans[2]);
        writeln('Tree Type:               ', players[i].strings[0]);
        writeln('');
      end;
    end;
    This will yield an output that looks something like:
    Progress Report:
    Minutes to run:          0
    Logs to chop:            6000
    Minutes before breaking: 70
    Hatchet Equipped:        True
    Save SRL log:            False
    Draw on SMART:           True
    Tree Type:               Willow



    Call runPlayerForm() in your mainloop

    Another important step. If you don't do this, nothing will work. You simply need to call the correct procedures before setupSRL() and you're good to go. Example:

    Simba Code:
    begin
      clearDebug();

      initPlayerForm(); // initiate your settings
      runPlayerForm();  // run the form

      // use this so the script doesn't continue if the user exits out of the form
      if (not playerForm.isScriptReady) then
        exit;

      declarePlayers();
      debugSPFSettings(); // this can be removed if you're satisfied with the result
      setupSRL();
    end.


    Conclusion


    I hope this was easy enough to understand. If you have any questions and/or concerns, please feel free to post here and I will help you out the best I can. I have also attached the complete example script if you'd like to use test it.

    Cheers,
    Coh3n
    Attached Files Attached Files
    Last edited by Coh3n; 12-06-2014 at 06:24 PM.

  2. #2
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Question: is the form done plugin sided? (AKA still no forms for lape?)

  3. #3
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    If you setup the form and run it once, save those settings. Then add a new setting in the script you get an out of range error, causing you to have to delete the old settings file before being able to run the script again. Would be bad for scripts that add features over time.


  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    No it's done in lape. Lape forms are pretty basic, bad syntax (i think ) and you cant use mml.

  5. #5
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    Question: is the form done plugin sided? (AKA still no forms for lape?)
    Like Olly said, Lape supports basic forms. You can check out the code here https://github.com/SRL/SRL-6/blob/ma...ayerform.simba.

    Quote Originally Posted by Ashaman88 View Post
    If you setup the form and run it once, save those settings. Then add a new setting in the script you get an out of range error, causing you to have to delete the old settings file before being able to run the script again. Would be bad for scripts that add features over time.

    Oh nice, good find. I'll try to fix that now. E: Fixed. If this happens it won't load previous settings. Not ideal, but the alternative isn't really feasible right now.
    Last edited by Coh3n; 01-12-2014 at 07:15 PM.

  6. #6
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Like Olly said, Lape supports basic forms. You can check out the code here https://github.com/SRL/SRL-6/blob/ma...ayerform.simba.

    Oh nice, good find. I'll try to fix that now.
    Also, I'm not sure if I'm setting something up wrong, but when I run the form for the first time (w/o settings file), I have a drop down for the Player file, but when I select my player file none of my players populate (it may not be designed to do that idk). However when I add a player manually in the box to the left, Player1, fill out the rest of the settings, save, then hit run I get:



    Simba Code:
    You have the latest version of the script!
    -- TPlayerArray.setup()
    ---- ERROR: Couldn't find army file()
    -- TPlayerArray.setup(): false
    -- Freeing the minimap mask

    but when i hit play again, my saved settings pop up - so I hit run

    Simba Code:
    -- TPlayerArray.setup()
    ---- Loaded player: Player1
    -- TPlayerArray.setup(): Success

    Player file: PlayerList
    Minutes until Break:          1
    # of Minutes to Break:            600
    Minutes until Break: 15
    Sacred Clay Hammer:        False
    Take Breaks:        True
    Switch Worlds (After Break):        True
    Logout if Mod is near:        True


    And it works fine?

  7. #7
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    ^ That was fixed in the latest update.

    E: The list won't populate. You have to manually add the players you want to use. I wanted to have a TCheckBoxList so the user would just select the players they want to use, but Lape doesn't support a TCheckBoxList yet, so for now, you'll just have to manually add the players you want to use.
    Last edited by Coh3n; 01-12-2014 at 07:00 PM.

  8. #8
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Nice stuff. You might want to change

    {$i srlplayerform.simba}

    to

    {$i srl-6\lib\misc\srlplayerform.simba}

    in your test script as new users might not know how to fix that.

  9. #9
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    Nice stuff. You might want to change

    {$i srlplayerform.simba}

    to

    {$i srl-6\lib\misc\srlplayerform.simba}

    in your test script as new users might not know how to fix that.
    Ah yes, thank you. Fixed.

  10. #10
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    I get this when I try to login a playerfile via Rafiki Player Form:

    Exception in Script: Runtime error: "Access violation" at line 1173, column 7 in file "C:\Simba\Includes\SRL-6\lib\core\players.simba"
    What am I doing wrong? Also, is there a way to change the location where Simba saves player files?

  11. #11
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Nufineek View Post
    I get this when I try to login a playerfile via Rafiki Player Form:
    What do you mean you're trying to login via Rafiki? Rafiki is only used to enter and save player information. There's no logging in of any kind.


    Quote Originally Posted by Nufineek View Post
    What am I doing wrong? Also, is there a way to change the location where Simba saves player files?
    Not that I know of.

    You're likely one of the < 1% of people who, for whatever reason, can't save a file in Simba/Includes @Olly; is working on a fix for this). Try running Simba as admin and see if that changes anything.

    E: Also, this thread is for the SRL Player Form, not Rafiki. The SRL Player Form is for script-specific settings. Rafiki is for saving private information like passwords and pins.
    Last edited by Coh3n; 02-26-2014 at 06:00 PM.

  12. #12
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    What do you mean you're trying to login via Rafiki? Rafiki is only used to enter and save player information. There's no logging in of any kind.


    Not that I know of.

    You're likely one of the < 1% of people who, for whatever reason, can't save a file in Simba/Includes @Olly; is working on a fix for this). Try running Simba as admin and see if that changes anything.
    Oh, sorry I meant log in via Playerform using XML file generated by Rafiki. Running as admin did not help. It's also my 1st time setting up SRL player form so I could have done a mistake somewhere else.

  13. #13
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Nufineek View Post
    Oh, sorry I meant log in via Playerform using XML file generated by Rafiki. Running as admin did not help. It's also my 1st time setting up SRL player form so I could have done a mistake somewhere else.
    Do you normally get an error running a script? Or did this only come up when you tried using the player form? If the latter, post your player file code as well as line 1173 of players.simba.

  14. #14
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Do you normally get an error running a script? Or did this only come up when you tried using the player form? If the latter, post your player file code as well as line 1173 of players.simba.
    Simba Code:
    1173:  if (getText) then

    Player XML file:
    Code:
    <army>
    
    	<player>
    
    		<diplayName></diplayName>
    
    		<loginName>New Player</loginName>
    
    		<nickName></nickName>
    
    		<password></password>
    
    		<bankPin></bankPin>
    
    	</player>
    
    </army>

  15. #15
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    I mean the code in your script that implements the SRL Player Form (the initPlayerForm and declarePlayers procedures).

  16. #16
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Simba Code:
    procedure declarePlayers();
    var
      i: integer;
    begin
      players.setup(playerForm.playerNames, playerForm.playerFile); // load the SPF players from the SRL Player Manager
      currentPlayer := 0;                                           // player to use first

      for i := 0 to high(players) do
        with players[i] do
        begin
          MIN_P_BK := strToInt(playerForm.players[i].settings[0]);
          MAX_P_BK := strToInt(playerForm.players[i].settings[1]);
          MIN_B_BK := strToInt(playerForm.players[i].settings[2]);
          MAX_B_BK := strToInt(playerForm.players[i].settings[3]);
          ENABLE_BREAKS := strToBool(playerForm.players[i].settings[4]);
          WHAT_TO_DO := playerForm.players[i].settings[5];
          WHICH_BANK   := playerForm.players[i].settings[6];
          randomType   := strToInt(playerForm.players[i].settings[7]);
        end;
    end;

    procedure initPlayerForm();
    begin
      with playerForm do
      begin
        name := 'Unf pots'; // the title of the SPF, usually the name of your script

        editBoxLabels := ['MIN Time before break','MAX Time before break', 'MIN Break length', ' MAX Break length']; // edit boxes are created for each array element
        editBoxDefaults := [ '30', '140', '3', '50'];                                             // optional default values for each edit box; array length must equal editBoxLabel length
        checkBoxLabels := ['Take Breaks'];        // same as editBoxLabels but for check boxes
        checkBoxDefaults := ['True'];

        comboBoxLabels := ['What to do?','Location', 'randomType'];                                                // same as editBoxLabels but for combo boxes (drop down boxes)
        comboBoxDefaults := ['Pots','AL', '1'];

        // this needs to be done for every element in the comboBoxLabels array
        setLength(comboBoxItems, length(comboBoxLabels));
        comboBoxItems[0] := ['Unfs', 'Cleans', 'Pots'];       // all the options available for the first combo box
        comboBoxItems[1] := ['GE', 'AL', 'CAM'];       // all the options available for the first combo box
        comboBoxItems[2] := ['1', '2', '3', '4'];       // all the options available for the first combo box
      end;
    end;

  17. #17
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Hmm, nothing jumps out at me. Do you call initPlayerForm() before declarePlayers() in your mainloop? Try calling this after initPlayerForm():
    Simba Code:
    for i := 0 to high(playerForm.players) do
      writeln(playerForm.players[i].settings);

  18. #18
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Hmm, nothing jumps out at me. Do you call initPlayerForm() before declarePlayers() in your mainloop? Try calling this after initPlayerForm():
    Simba Code:
    for i := 0 to high(playerForm.players) do
      writeln(playerForm.players[i].settings);
    Yeah, it writes what I fill in the form..
    Simba Code:
    [20, 70, 3, 30, True, Pots, CAM, 2]

  19. #19
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Well, I've managed to reproduce the error. It happens when your "players" array has a length of 0. So, there's something bad going on when you call players.setup(). Can you make sure SRL debug is turned on, and post the debug text before the error? This will tell us exactly what's going on.

  20. #20
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Well, I've managed to reproduce the error. It happens when your "players" array has a length of 0. So, there's something bad going on when you call players.setup(). Can you make sure SRL debug is turned on, and post the debug text before the error? This will tell us exactly what's going on.
    Seems it's something with the playername from the player form.
    Code:
    ---- WARNING: Invalid player name: poiwqueqwr
    -- TPlayerArray.setup(): Success
    -- TPlayer.login()
    ---- TPlayer.loginToLobby()
    Exception in Script: Runtime error: "Access violation" at line 1173, column 7

  21. #21
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    The names are case-sensitive, so make sure they are exactly the same in the player form as in Rafiki.

  22. #22
    Join Date
    Feb 2012
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    84 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    The names are case-sensitive, so make sure they are exactly the same in the player form as in Rafiki.
    That was it. Thanks! Also, is there a way to change the location where playerform saves the setting.xml file?

  23. #23
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Nufineek View Post
    That was it. Thanks! Also, is there a way to change the location where playerform saves the setting.xml file?
    Yes, just set playerForm.scriptSettingsPath in your initPlayerForm() procedure. The default is the script's path.

  24. #24
    Join Date
    Feb 2013
    Location
    Narnia
    Posts
    615
    Mentioned
    8 Post(s)
    Quoted
    252 Post(s)

    Default

    i get this error when trying to run the test form. can this be used with OldSchool granted the codes done in Lape?

    Exception in Script: Plugin(libtesseract32) has not been found

    View my OSR Script Repository!


    Botted to max
    Guides: How to Report Bugs to the Scripter
    ~~~~ Moved to Java. Currently Lurking ~~~~

  25. #25
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Sk1nyNerd View Post
    i get this error when trying to run the test form. can this be used with OldSchool granted the codes done in Lape?

    Exception in Script: Plugin(libtesseract32) has not been found
    If SRL-OSR is written in PascalScript, then no, this won't work. Plus, this utilizes the Players array in SRL-6 which is different than the players array in SRL-OSR.

Page 1 of 3 123 LastLast

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
  •