PDA

View Full Version : Using SRL-6 and Updating Your SRL-5 Script



Coh3n
11-17-2013, 03:34 AM
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 (http://villavu.com/forum/showthread.php?t=58935)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 (https://dl.dropboxusercontent.com/u/33256273/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.

http://i.imgur.com/LwQIOf2.png



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:

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:

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:

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:

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:

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 (http://docs.villavu.com/srl-6/drawing.html), or in Simba's tmufasabitmap.pas (https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLAddon/LPInc/Classes/MML/lptmufasabitmap.pas#L439). You also need to set the variable smartEnableDrawing to true.

Example:

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. :p

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/ (https://github.com/SRL/SRL-6/tree/master/lib/utilities/types) holds a TON of useful functions to each of the common data types. Similarly, the lib/utilities/wrappers.simba (https://github.com/SRL/SRL-6/blob/master/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 (http://villavu.com/forum/chat_irc.php).
Post on this thread, and someone will reply as soon as possible.
Visit the Scripting Help (http://villavu.com/forum/forumdisplay.php?f=491) 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 (http://villavu.com/forum/showthread.php?t=106337) . 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

YoHoJo
11-17-2013, 01:00 PM
AMAZING! Great work Cohen! It looks great! Going to help a lot of people.

Abu
11-22-2013, 08:57 PM
Absolutely great guide. Just what I was looking for. :)

Kudos.