Results 1 to 3 of 3

Thread: Using SRL-6 and Updating Your SRL-5 Script

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

    Default Using SRL-6 and Updating Your SRL-5 Script

    A How-to Guide on SRL-6 Scripting

    Introduction


    Hello! And welcome to another scripting tutorial. Hopefully I will be able to make it easier for you to script using SRL-6. This guide isn't going to be incredibly thorough, but there will be a lot of examples to help you understand how things are done. If you have any questions, please don't hesitate to post, and I will reply as soon as possible. This guide is written under the assumption that you already have basic scripting knowledge. If you do not, I recommend reading this tutorial.

    Index:
    • Introduction
    • Reference
    • Some basic stuff about Lape you should know
    • How to setup declarePlayers() and login
    • How to use type-functions
    • How to draw on SMART
    • SRL's internal data
    • SRL's overloaded functions & basic type-functions
    • Where to get help
    • Conclusion



    Reference


    Here are several links I highly recommend using as reference, especially the SRL-6 documentation.

    Links Description
    http://github.com/SRL/SRL-6 The official SRL-6 repository
    http://docs.villavu.com/srl-6/ The official SRL-6 documentation
    http://villavu.com/forum/project.php?projectid=10 The official SRL-6 bugs and suggestions page
    http://villavu.com/forum/forumdisplay.php?f=491 The Scripting Help section of the forums
    http://villavu.com/forum/showthread.php?t=105024 A detailed tutorial on Lape features
    http://villavu.com/forum/chat_irc.php SRL's IRC chat
    http://villavu.com/forum/showthread.php?t=106337 @bonsai;'s SRL-6 walkthrough
    srl-6_changes.pdf Changes from SRL-5 to SRL-6


    Some basic Lape stuff you should know


    SRL-6 takes advantage of some of Lape's more advanced features, and you are likely to come across a few of them while scripting. These are not all of Lape's features; just the ones used extensively by SRL.

    Setting Simba to use Lape

    First you'll want to make sure Simba's interpreter is set to Lape, otherwise you will run into all kinds of problems. Simply go to Script > Interpreter > Lape.



    Overloading

    Overloading a function means there can be more than one function of the same name. These multiple functions usually take a different or additional parameter.

    Example:
    Simba Code:
    program overloadExample;

    function findTree(var x, y: integer): boolean;
    begin
      writeln('findTree(var x, y: integer)');
    end;

    function findTree(var x, y: integer; tol: integer): boolean; overload;
    begin
      writeln('findColor(var x, y, tol: integer)');
    end;

    var
      x, y: integer;
    begin
      clearDebug();
      findTree(x, y);
      findTree(x, y, 15);
    end.
    As you can see, both are valid. You can have as many overloaded functions as you want, and yes, you can overload functions already in Simba!


    Overriding

    Overriding is similar to overloading, except you can't have multiples of a function. If you override a function, you are replacing the one that already exists. Your override function needs to have the exact same parameters as the function you want to replace (override).

    Example:
    Simba Code:
    program overrideExample;

    function findColor(var x, y: integer; color, x1, y1, x2, y2: integer): boolean; override;
    begin
      writeln('findColor(var x, y: integer)');
    end;

    var
      x, y: integer;
    begin
      clearDebug();
      findColor(x, y, 0, 0, 0, 0, 0);
    end.
    As you can see, I have overridden an internal Simba function to work as I need it. Doing something like this means you can, for example, use a custom mouse moving function that is utilized inside SRL.


    Default parameters

    Having default parameters allows us to give the scripter a little more freedom in function parameters. If a function has a default parameter(s), it is optional when calling the function. For example, SRL-6 has an overloaded findText() function with a default 'waitTime' parameter, giving the scripter an option to wait for the text to appear. If you wish, you can have multiple default parameters, and to "skip" one of them, you just use an extra comma. That might not be clear, so hopefully the example helps.

    Example:
    Simba Code:
    program defaultParameterExample;

    function findTree(var x, y: integer; treeType: string = 'Magic'; maxWait: integer = 3000): boolean;
    var
      t := (getSystemTime() + maxWait);
      c: integer;
    begin
      writeln('Looking for a '+treeType+' tree.');

      while (getSystemTime() < t) do
      begin
        //if (codeToFindTree) then
          //break;

        wait(500);
        inc(c);
        writeln(c);
      end;
    end;

    var
      x, y: integer;
    begin
      clearDebug();
      findTree(x, y); // can omit the default parameters
      findTree(x, y, , 5000); // or "skip" one - notice the "empty" comma
      findTree(x, y, 'Yew');
    end.
    As you can see, all the different calls are valid.


    Type-functions

    SRL-6 is almost entirely written using type-functions. This means that we can write functions that are specific to a certain data type, and can only be called using a variable of that data type. The Simba function list will show, for example, TRSMinimap.tpaWalk(), but it needs to be called through a variable of the TRSMinimap data type (in SRL, it's 'minimap').

    Also, the access the data of the type inside the type function, you use the 'self.' keyword.

    Example:
    Simba Code:
    program typeFunctionExample;

    type
      TMSObject = record
        name: string;
        color: integer;
      end;

    procedure TMSObject.debug();
    begin
      writeln(self.name);  // using 'self' to access the TMSObject's data
      writeln(self.color);
    end;

    var
      o: TMSObject;

    begin
      clearDebug();
      o.name := 'Yew tree';
      o.color := 7283749;
      o.debug(); // procedure needs to be called by the variable
    end.
    This is a very simple, yet effective concept that you will need to understand to script with SRL-6. If you need help understanding, don't hesitate to ask.


    How to setup declarePlayers() and login


    SRL-6's declarePlayers() procedure can be utilized to use the Rafiki Player Manager (SRL > Player Manager); however, the old-style declarePlayers() will also work. The example will show both ways.

    Example:
    Simba Code:
    program new;
    {$DEFINE SMART}
    {$i srl-6/srl.simba}

    // the new way (using Rafiki Player Manager)
    procedure declarePlayers();
    begin
      players.setup(['Kryptov'], 'Skillers');
      currentPlayer := 0;

      with players[0] do
      begin
        integers[0] := 50;
        integers[1] := 25;
        booleans[0] := true;
      end;
    end;

    // the old way (without Rafiki Player Manager)
    procedure declarePlayersOld();
    begin
      setLength(players, 1); // how many players to use
      currentPlayer := 0;

      with players[0] do
      begin
        loginName := 'cohenadair@gmail.com';
        displayName := 'Kryptov';
        password := 'jackaster';
        isActive := true;
        isMember := false;
        bankPin := '';
        world := -1; // -1 will just click the play button
        integers[0] := 50;
        integers[1] := 25;
        booleans[0] := true;
      end;
    end;

    begin
      clearDebug();
      setupSRL();
      declarePlayersOld();
      players[currentPlayer].login();
    end.

    players.setup(['Account1', 'Account2'], 'Skillers');

    The first parameter (['Account1', 'Account2']) is a TStringArray of all the accounts you wish to use with the current script. The player's login name, display name, or nickname will work. The second parameter ('Skillers') is a string of player file name. The name is whatever you set it to in the player manager.

    The declarePlayers() method you choose is up to you, but users may prefer the Player Manager version so they don't have to enter their player information into every script.


    How to draw on SMART


    Drawing on SMART is easier than ever, just call a TMufasaBitmap function on the variable, "smartImage". A list of usable functions can be found in drawing.simba, or in Simba's tmufasabitmap.pas. You also need to set the variable smartEnableDrawing to true.

    Example:
    Simba Code:
    smartEnableDrawing := true;
    smartImage.drawBox(minimap.getBounds(), false, clRed);


    SRL's internal data


    SRL-6 has certain data that is meant to only be used inside SRL. This does not mean you can't use it; it means it's not recommended. The code was meant to be used inside SRL, and there's probably a reason for that. There is always an alternative to using an internal SRL function. If you are unsure what that is, please don't hesitate to ask.

    Internal data is represented using and single '_' and double '__'. Single (_) means you shouldn't use it, but it won't hurt anything if you do. Double (__) means absolutely under no circumstances should you use this data. There is a good chance you will mess something up.

    If you wish, you can hide this internal data from the function list. Just go to View > Show Hidden and make sure it isn't checked.


    SRL's overloaded functions and basic type-functions


    The lib/utilities/types/ holds a TON of useful functions to each of the common data types. Similarly, the lib/utilities/wrappers.simba file stores a TON of Simba functions that will take TPoints and TBoxes as parameters.

    I encourage you to look through those files to find what you're looking for.


    Where to get help


    As always, there are plenty of people here at SRL who are willing to help. The best places to get help are:

    • Probably the easiest and fastest way to get help is to join SRL's IRC Channel on irc.rizon.net (#srl), or click here.
    • Post on this thread, and someone will reply as soon as possible.
    • Visit the Scripting Help section of the forums.


    Conclusion


    I know it's short and not incredibly detailed, but to be honest, scripting with SRL-6 is easier than you think. If you don't this this helped you, I encourage you to check out @bonsai's walk-through of SRL-6 . It may help clear up some confusion. If there is something I should add or elaborate further on, please let me know and I will add it as soon as possible.

    Cheers,
    Coh3n
    Last edited by Coh3n; 12-08-2013 at 02:14 PM.

  2. #2
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    AMAZING! Great work Cohen! It looks great! Going to help a lot of people.

  3. #3
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Absolutely great guide. Just what I was looking for.

    Kudos.

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
  •