Torrent of Flame
03-25-2008, 07:40 PM
Compliments to gerauchert for the suggestion. Borrowed some stuff from JAD's tutorial on fixing annoying errors.
Dont forget to Rep++ me or Rank the Thread!
Welcome to the scripting technique tutorial. I will explain how and when to use a certain item of scripting, like FailSafes, etc.
I have to admit though. I probably wont be writing it ALL at once. So look out for the updates on the Horizon! This Tutorial works from the very basic at the start, to the more complex and SRL Member worthy at the end.
Table of Contents
Basic Errors.
How to Begin a Script.
Variables and Constants
Descriptions!
Declare Players
Finding that Object.
Bitmaps.
Clicking.
Banking.
DTM's.
Using DTM's Efficiently.
Standards.
Anti-Ban.
Anti-Randoms.
Main Looping.
Things to make your script appealing
Signatures
Progress Reports
Intoduction
Version History
I hope to add alot more aswell, and hope to teach myself some stuff in the process!
Onto the Tutorial.
Part 1: Basic Errors
Identifier Expected: A Begin without an End. A Repeat without an Until. An If without a Then.
I'm sure alot of the people scripting out there have had this error many times. Identifier Expected is a very basic scripting mistake that people still make, even when they are SRL Members. It is basically where you write your script, but miss out vital parts. It's more annoying when you cant even realise where the error actually is!
Say this was your current script:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
You would think, "Amazing - I made my first procedure" You press Compile. '[Error] (12595:4): Identifier expected'. Oh no, another post on the Scripting Help Forums about how you cant fix it at any cost. Just look. After "Writeln".. what is missing? Yes. The End. This is how it should look:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
end;
Simple mistake, but ever so annoying.
Invalid number of parameters Ok, a little more difficult, but again, not that hard to fix. When you first start a script, if you instantly include
{.include SRL/SRL.scar}
then when you type a procedure, you get a little box come up when your typing, to tell you what to write, and more importantly, telling you how much should be in the brackets. Say you had this line:
if FindObjCustom(x, y, ['Wil', 'low'], [1989969, 3760987, 2844763], 7, 10) then
You would think nothing is wrong, I mean, its how I followed that tutorial the other day? Well, it has one too many numbers, or parameters. That 10 shouldnt be there. The FindObjCustom procedure should look like this without any text or input data in it:
http://i29.tinypic.com/9riyw2.jpg
See, it has 5 needed inputs, the X and the Y, The ['Text it should look for'], [The Colours] and the Tolerance.
So 5, in our procedure up there, its 6? So take out that 10, and we have our line compiling correctly;
if FindObjCustom(x, y, ['Wil', 'low'], [1989969, 3760987, 2844763], 7) then
Close round expected in script Simple again, but alot of people get this error and wonder how they cannot fix it!
Look at this example:
if (FindColorSpiralTolerance(x, y, RockColor, 0, 0, 249, 179, Tol) then
Now, You get that error and wodner.. I dont get it? Why doesnt it work. Well, look at the start. You have two brackets at the beginning, but only one at the end. To prevent this error it should look like this:
if (FindColorSpiralTolerance(x, y, RockColor, 0, 0, 249, 179, Tol)) then
Semicolon (';') expected in script This happens alot to people. They forget to put a semi-colon in their script. I myself still sometiems do this.
This is your current script:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true)
FFlag(0);
Writeln('Got to bank');
end;
end;
Now you compile and get this error, and your confused? Well, look at the Mouse line. See there is no Semi-Colon there? Well, this is what causes the error. It should look like this to be correct:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
end;
Part Two: Beginning a Script
Beginning a script is obviousley very important. Without it, a script wont work. To start a script, it is a very basic thing. All you have to do is this basically:
program ThisIsMyScriptName;
Program - This script is basically a program? And With the bit after, try to make it relevant to your actually mean something. So if its a Varrock Miner, call it
program VarrockMiner;
Draynor WoodCutter..
program DraynorMultiWoodCutter;
Get the idea?
Part Three: Variables and Constants
Variables
Then we have to declare our variables, not variables again explain themselves, something that is a variable, can constantly change. The variables in this case are the x and the y, the co-ordinates on the game screen. It is an "integer" as they are co-ordinates, which are numerical.
var x, y: integer;
Constants
The we include our constants. Constants are basically what they say they are, something that is ALWAYS the same, like RockColours, TreeColours, SMART Worlds, etc.
const
RockColour1= 111111;
RockColour2= 222222;
These Rock Colours would be picked from the Rock You wish to mine, so Iron and Rune would be different, The example colours are obviousley false for any type
Part Four: Descriptions
Descriptions are important. They tell the user what to do on a script, but more importantly, help you to edit a script when you come to work again on a script. They are also useful for crediting procedures and adding little notes.
Examples
Telling the User what to do
//-->Loads<--\\
Loads = 1; //How many loads per player before switching
//--->SRL ID<---\\
YourSRLId = '';
YourSRLPassword ='';
//--->Pin - Make same for ALL chars. If no Pin, leave blank<---\\
YourPin = '';
//SMART World\\
SMARTWorld = 152; //What SMART World?
{-------------------------------------------------------
Player Setup
--------------------------------------------------------}
procedure DeclarePlayers;
begin
HowManyPlayers := 2; //How many Players
NumberOfPlayers(HowManyPlayers);
CurrentPlayer :=0; //Starting Player
Players[0].Name := ''; //UserName
Players[0].Pass := ''; //Password
Players[0].Nick := ''; // 3 - 4 NonCapital/No Spaced letters of your User
Players[0].Active := True; // Is this player active?
You see? It helps the user to enter what information he needs to do.
Helping you Edit a script when you need too
When your scripts start to get more complex, spacing and titles help you to find the procedure you are looking for. It is not difficult to put something like:
//---------------------------------ChopTree-----------------------------------\\
So when you edit it, it is easy to find the procedure that you are looking for.
Crediting and Adding Notes
procedure EntFinder; //By Yohojo - Modded by BobboHobbo
var
EX, EY: integer;
FX, FY: integer;
SafeEntWait: LongInt;
begin
if (not (LoggedIn)) then
Exit;
begin
Status('Ent Checking')
if
(FindObjCustom(EX, EY, ['Willow'], [4690821], 7)) then
begin
MMouse(EX, EY, 0, 0)
if FindColorTolerance(FX, FY, 55769, 85, 15, 115, 15, 20) then
begin
Status('Found Ent');
MarkTime(SafeEntWait)
repeat
FTWait(5)
FindNormalRandoms;
if not (LoggedIn) then
NextPlayer(False);
until TimeFromMark(SafeEntWait) > 20000 + Random(5000);
end;
end;
end;
end;
You can credit procedures, aswell as adding little notes to scripts to remind you what they do:
Procedure IsAxeBroke;
begin
if FindDTM(BrokenAxe, x, y, 547, 206, 734, 464) then
begin
if FindDTM(BrokenAxe, x, y, 547, 206, 734, 464) then
begin
ChooseOption('rop'); // Edit at next release to bank the broken axe
BrokenAxes := BrokenAxes +1;
end;
For example.
Part Five: Declare Players
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer:= 0
Players[0].Name := 'Username';
Players[0].Pass := 'Password';
Players[0].Nick := 'erna';
Players[0].Active := True;
end;
Procedure DeclarePlayers tells us the name of the procedure that we are using. Begin starts the procedure [Every "Begin" has an "End", Every "Repeat" has an "Until" and Every "If" has a "Then" - Follow this and it should stop "Idenfitifer Expected"] How Many Players means how many players we are going to use, and Current player tells us which player to start with. Username, Password are pretty basic, but the Nickname HAS to be 3-4 letters of non-capital or without a space of your Username, like mine is. The Active = True tells us if the player is to be run in the script or not.
Part Six: Finding That Object
procedure RockMining;
begin
if not LoggedIn then
Exit;
if (not (FindObjCustom(x, y, ['Mi', 'ne'], [RockColour1, RockColour2], 7))) then
Wait(100+random(100));
Tries := Tries + 1;
if(Tries = 20)then
begin
Logout;
Exit;
end else
if FindObjCustom(x, y, ['Min', 'ine'], [RockColour1, RockColour2], 7) then
repeat
case (Random(2)) of
1: Mouse(x, y, 4, 4,false);
ChooseOption('ine');
2: Mouse(x, y, 4, 4, True);
end;
until (InvFull)
end;
From the Start:
procedure RockMining;
begin
if not LoggedIn then
Exit;
We name our procedure, and then it begins. We have our first Fail Safe. If our character is not logged in, the script will exit.
if (not (FindObjCustom(x, y, ['Mi', 'ne'], [RockColour1, RockColour2], 7))) then
Wait(100+random(100));
Tries := Tries + 1;
if(Tries = 20)then
begin
Logout;
Exit;
end else
Well first, if it doesnt find the Object that says "Mine" when hovered over, including a Tolerance of 7, so it can search 7 pixels either side, it will wait 0.2seconds, add 1 to the number of tries, and try again. If it Tries 20 times with no success, it will logout your character, to stop you standing there like an idiot, and then exit the script, and Ends ELSE - IE, otherwise..
if FindObjCustom(x, y, ['Min', 'ine'], [RockColour1, RockColour2], 7) then
repeat
case (Random(2)) of
1: Mouse(x, y, 4, 4,false);
ChooseOption('ine');
2: Mouse(x, y, 4, 4, True);
end;
until (InvFull)
end;
If it actually finds the Rock to mine, it will repeat a random of these 2, it will hover over the rock and Choose "Mine" or it will automatically click on the rock, to make it more human like. It then ends the case, and the repeat goes with the until, like I said earlier, so it will repeat mining until it has a full inventory, then ends the procedure.
Now the FindObjCustom is the procedure that finds objects for us, so it searches for the name of the thing, aswell as colours with a certain tolerance, and finds them on the x and y axis.
Part Seven: Bitmaps
Bitmaps are basically a string of code for a picture that you want SCAR to find. To make a Bitmap, you have to go to Tools and go to Picture to String, and you get this screen load up
http://i27.tinypic.com/2dake4y.jpg
Open up the image you want. Dont make it too big, and make the background black, as the Picture to String wont pick up the black. You should get something resembiling this:
MMTREE := BitmapFromString(12, 11, 'beNpjYMAPVFQkgAhNUD9JyL' +
'5AAo8uoAKIGqzKILJwBZjK4ArQlAHZuNRAlOFxmJsZZ5KfKH7 PAhV' +
'QRQ2ZAAD1bBqM');
So it has a name, The Bitmap From String, and the dimensions. Then the code itself.
To use this in the script you would just simple put:
if(FindBitmap(MMTREE, x, y) then
BUT You MUST declare the MMTREE, or whatever bitmap name you have as a Variable integer, so our variable list would look like this:
var x, y, MMTREE: integer;
Continuing with Part Eight Below....
Dont forget to Rep++ me or Rank the Thread!
Welcome to the scripting technique tutorial. I will explain how and when to use a certain item of scripting, like FailSafes, etc.
I have to admit though. I probably wont be writing it ALL at once. So look out for the updates on the Horizon! This Tutorial works from the very basic at the start, to the more complex and SRL Member worthy at the end.
Table of Contents
Basic Errors.
How to Begin a Script.
Variables and Constants
Descriptions!
Declare Players
Finding that Object.
Bitmaps.
Clicking.
Banking.
DTM's.
Using DTM's Efficiently.
Standards.
Anti-Ban.
Anti-Randoms.
Main Looping.
Things to make your script appealing
Signatures
Progress Reports
Intoduction
Version History
I hope to add alot more aswell, and hope to teach myself some stuff in the process!
Onto the Tutorial.
Part 1: Basic Errors
Identifier Expected: A Begin without an End. A Repeat without an Until. An If without a Then.
I'm sure alot of the people scripting out there have had this error many times. Identifier Expected is a very basic scripting mistake that people still make, even when they are SRL Members. It is basically where you write your script, but miss out vital parts. It's more annoying when you cant even realise where the error actually is!
Say this was your current script:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
You would think, "Amazing - I made my first procedure" You press Compile. '[Error] (12595:4): Identifier expected'. Oh no, another post on the Scripting Help Forums about how you cant fix it at any cost. Just look. After "Writeln".. what is missing? Yes. The End. This is how it should look:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
end;
Simple mistake, but ever so annoying.
Invalid number of parameters Ok, a little more difficult, but again, not that hard to fix. When you first start a script, if you instantly include
{.include SRL/SRL.scar}
then when you type a procedure, you get a little box come up when your typing, to tell you what to write, and more importantly, telling you how much should be in the brackets. Say you had this line:
if FindObjCustom(x, y, ['Wil', 'low'], [1989969, 3760987, 2844763], 7, 10) then
You would think nothing is wrong, I mean, its how I followed that tutorial the other day? Well, it has one too many numbers, or parameters. That 10 shouldnt be there. The FindObjCustom procedure should look like this without any text or input data in it:
http://i29.tinypic.com/9riyw2.jpg
See, it has 5 needed inputs, the X and the Y, The ['Text it should look for'], [The Colours] and the Tolerance.
So 5, in our procedure up there, its 6? So take out that 10, and we have our line compiling correctly;
if FindObjCustom(x, y, ['Wil', 'low'], [1989969, 3760987, 2844763], 7) then
Close round expected in script Simple again, but alot of people get this error and wonder how they cannot fix it!
Look at this example:
if (FindColorSpiralTolerance(x, y, RockColor, 0, 0, 249, 179, Tol) then
Now, You get that error and wodner.. I dont get it? Why doesnt it work. Well, look at the start. You have two brackets at the beginning, but only one at the end. To prevent this error it should look like this:
if (FindColorSpiralTolerance(x, y, RockColor, 0, 0, 249, 179, Tol)) then
Semicolon (';') expected in script This happens alot to people. They forget to put a semi-colon in their script. I myself still sometiems do this.
This is your current script:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true)
FFlag(0);
Writeln('Got to bank');
end;
end;
Now you compile and get this error, and your confused? Well, look at the Mouse line. See there is no Semi-Colon there? Well, this is what causes the error. It should look like this to be correct:
procedure WalkToBank;
begin
if (FindSymbol(x, y, 'bank')) then
begin
Mouse(x, y, 2, 2, true);
FFlag(0);
Writeln('Got to bank');
end;
end;
Part Two: Beginning a Script
Beginning a script is obviousley very important. Without it, a script wont work. To start a script, it is a very basic thing. All you have to do is this basically:
program ThisIsMyScriptName;
Program - This script is basically a program? And With the bit after, try to make it relevant to your actually mean something. So if its a Varrock Miner, call it
program VarrockMiner;
Draynor WoodCutter..
program DraynorMultiWoodCutter;
Get the idea?
Part Three: Variables and Constants
Variables
Then we have to declare our variables, not variables again explain themselves, something that is a variable, can constantly change. The variables in this case are the x and the y, the co-ordinates on the game screen. It is an "integer" as they are co-ordinates, which are numerical.
var x, y: integer;
Constants
The we include our constants. Constants are basically what they say they are, something that is ALWAYS the same, like RockColours, TreeColours, SMART Worlds, etc.
const
RockColour1= 111111;
RockColour2= 222222;
These Rock Colours would be picked from the Rock You wish to mine, so Iron and Rune would be different, The example colours are obviousley false for any type
Part Four: Descriptions
Descriptions are important. They tell the user what to do on a script, but more importantly, help you to edit a script when you come to work again on a script. They are also useful for crediting procedures and adding little notes.
Examples
Telling the User what to do
//-->Loads<--\\
Loads = 1; //How many loads per player before switching
//--->SRL ID<---\\
YourSRLId = '';
YourSRLPassword ='';
//--->Pin - Make same for ALL chars. If no Pin, leave blank<---\\
YourPin = '';
//SMART World\\
SMARTWorld = 152; //What SMART World?
{-------------------------------------------------------
Player Setup
--------------------------------------------------------}
procedure DeclarePlayers;
begin
HowManyPlayers := 2; //How many Players
NumberOfPlayers(HowManyPlayers);
CurrentPlayer :=0; //Starting Player
Players[0].Name := ''; //UserName
Players[0].Pass := ''; //Password
Players[0].Nick := ''; // 3 - 4 NonCapital/No Spaced letters of your User
Players[0].Active := True; // Is this player active?
You see? It helps the user to enter what information he needs to do.
Helping you Edit a script when you need too
When your scripts start to get more complex, spacing and titles help you to find the procedure you are looking for. It is not difficult to put something like:
//---------------------------------ChopTree-----------------------------------\\
So when you edit it, it is easy to find the procedure that you are looking for.
Crediting and Adding Notes
procedure EntFinder; //By Yohojo - Modded by BobboHobbo
var
EX, EY: integer;
FX, FY: integer;
SafeEntWait: LongInt;
begin
if (not (LoggedIn)) then
Exit;
begin
Status('Ent Checking')
if
(FindObjCustom(EX, EY, ['Willow'], [4690821], 7)) then
begin
MMouse(EX, EY, 0, 0)
if FindColorTolerance(FX, FY, 55769, 85, 15, 115, 15, 20) then
begin
Status('Found Ent');
MarkTime(SafeEntWait)
repeat
FTWait(5)
FindNormalRandoms;
if not (LoggedIn) then
NextPlayer(False);
until TimeFromMark(SafeEntWait) > 20000 + Random(5000);
end;
end;
end;
end;
You can credit procedures, aswell as adding little notes to scripts to remind you what they do:
Procedure IsAxeBroke;
begin
if FindDTM(BrokenAxe, x, y, 547, 206, 734, 464) then
begin
if FindDTM(BrokenAxe, x, y, 547, 206, 734, 464) then
begin
ChooseOption('rop'); // Edit at next release to bank the broken axe
BrokenAxes := BrokenAxes +1;
end;
For example.
Part Five: Declare Players
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer:= 0
Players[0].Name := 'Username';
Players[0].Pass := 'Password';
Players[0].Nick := 'erna';
Players[0].Active := True;
end;
Procedure DeclarePlayers tells us the name of the procedure that we are using. Begin starts the procedure [Every "Begin" has an "End", Every "Repeat" has an "Until" and Every "If" has a "Then" - Follow this and it should stop "Idenfitifer Expected"] How Many Players means how many players we are going to use, and Current player tells us which player to start with. Username, Password are pretty basic, but the Nickname HAS to be 3-4 letters of non-capital or without a space of your Username, like mine is. The Active = True tells us if the player is to be run in the script or not.
Part Six: Finding That Object
procedure RockMining;
begin
if not LoggedIn then
Exit;
if (not (FindObjCustom(x, y, ['Mi', 'ne'], [RockColour1, RockColour2], 7))) then
Wait(100+random(100));
Tries := Tries + 1;
if(Tries = 20)then
begin
Logout;
Exit;
end else
if FindObjCustom(x, y, ['Min', 'ine'], [RockColour1, RockColour2], 7) then
repeat
case (Random(2)) of
1: Mouse(x, y, 4, 4,false);
ChooseOption('ine');
2: Mouse(x, y, 4, 4, True);
end;
until (InvFull)
end;
From the Start:
procedure RockMining;
begin
if not LoggedIn then
Exit;
We name our procedure, and then it begins. We have our first Fail Safe. If our character is not logged in, the script will exit.
if (not (FindObjCustom(x, y, ['Mi', 'ne'], [RockColour1, RockColour2], 7))) then
Wait(100+random(100));
Tries := Tries + 1;
if(Tries = 20)then
begin
Logout;
Exit;
end else
Well first, if it doesnt find the Object that says "Mine" when hovered over, including a Tolerance of 7, so it can search 7 pixels either side, it will wait 0.2seconds, add 1 to the number of tries, and try again. If it Tries 20 times with no success, it will logout your character, to stop you standing there like an idiot, and then exit the script, and Ends ELSE - IE, otherwise..
if FindObjCustom(x, y, ['Min', 'ine'], [RockColour1, RockColour2], 7) then
repeat
case (Random(2)) of
1: Mouse(x, y, 4, 4,false);
ChooseOption('ine');
2: Mouse(x, y, 4, 4, True);
end;
until (InvFull)
end;
If it actually finds the Rock to mine, it will repeat a random of these 2, it will hover over the rock and Choose "Mine" or it will automatically click on the rock, to make it more human like. It then ends the case, and the repeat goes with the until, like I said earlier, so it will repeat mining until it has a full inventory, then ends the procedure.
Now the FindObjCustom is the procedure that finds objects for us, so it searches for the name of the thing, aswell as colours with a certain tolerance, and finds them on the x and y axis.
Part Seven: Bitmaps
Bitmaps are basically a string of code for a picture that you want SCAR to find. To make a Bitmap, you have to go to Tools and go to Picture to String, and you get this screen load up
http://i27.tinypic.com/2dake4y.jpg
Open up the image you want. Dont make it too big, and make the background black, as the Picture to String wont pick up the black. You should get something resembiling this:
MMTREE := BitmapFromString(12, 11, 'beNpjYMAPVFQkgAhNUD9JyL' +
'5AAo8uoAKIGqzKILJwBZjK4ArQlAHZuNRAlOFxmJsZZ5KfKH7 PAhV' +
'QRQ2ZAAD1bBqM');
So it has a name, The Bitmap From String, and the dimensions. Then the code itself.
To use this in the script you would just simple put:
if(FindBitmap(MMTREE, x, y) then
BUT You MUST declare the MMTREE, or whatever bitmap name you have as a Variable integer, so our variable list would look like this:
var x, y, MMTREE: integer;
Continuing with Part Eight Below....