SRL Archive - Outdated Tutorials

Color arrays and how to control them


Pure1993

2008-04-30 14:57:48

Attention: The tutorial has been expanded! Take a look ^^.
Hi, welcome to another one of my guides (dunno exactly how many i wrote…).
In this tutorial, you will learn: how to add and subtract Integers to arrays (strings work the same way, but there are better examples for Integers), how to apply that knowledge, and in what it will improve your scripts.
To understand this tutorial, you need to know:
-How to set up basic arrays.
-How the color system in SCAR works.
-The basics about SCAR and SRL in general.

If you have ever used Tarajunky's chicken killer, you might have noticed, that the script is constantly adding colors to its color array. If you think about it for a moment, you will realize how ingenious that really is, because the more colors it searches for, the faster and better are the results. Now, if you want to, feel free to take a short break here and look at his script, but I must warn you, you can get quite dizzy after looking at so much code, if you don't understand most of it (if I am honest, 3 months ago i didn't completely understand a single procedure/function :D ). For those of you who just get lost in that script, just continue reading this tutorial, and it will be explained step by step.

Okay, so let's start from scratch:
program DynamicArrayExplanation;
{.include srl/srl.scar}
begin
end.
Now, add the variables which we will need:
program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array of Integer[0..2];
ColorPointsTPA: TPointArray;
begin
end.
Next, define the already found colors:
program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
end.
We need some colors to start out with, otherwise, where should the script know which other colors to pick? Next up, is adding the colorfinding and the "for to do" statement:
program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
end;
end.
Now, let's make it so that we check if the color points it found, are actually of the item we want:
program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
MMouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0);
wait(125);
if GetUpText='limb-' then
begin
end;
end;
end.
"limb-" is from "climb-down" from the stairs in Lumbridge. Now I will just add the rest and explain it aftrwards:
program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
MMouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0);
wait(125);
if GetUpText='limb-' then
begin
MyColor := GetColor(ColorPointsTPA[i].x, ColorPointsTPA[i].y);
l := GetArrayLength(MyColors);
SetArrayLength(MyColors, l + 1);
MyColors[GetarrayLength(MyColors)-1]:= MyColor;
Mouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0, true);
Wait(1500);
end;
end;
end.
For those of you who don't understand this, just relax, sit back, and don't get all worked up on this code, because it is quite easy once you get it explained (or, the way i did it, get worked up over it until you are so tired that you get it while falling asleep, but that is the not as easy way ^^).
First of all, I will go over some definitions:
SetArrayLength(arrayname: array; length: Integer): boolean;
{-this one can cut or lengthen your array, depending if the number you put in "length" part is bigger or smaller than the already existing array.}

GetArrayLength(arrayname: array): Integer;
{-this one returns the length of your array, for example if your array ranged from [0] to [4], the length would be 5 (0,1,2,3,4).}
Now that you know what each one does, I will explain exactly what happened here:
1) It seraches for one of the colorswith a tolerance on 50.
2) If the color was found, it moves the mouse over it.
3) If the correct text appears, it gets the color of that point.
4) We save the array length to the variable "l".
5) We add 1 Integer to the length of the array named "MyColors".
6) We determine the new Integer to be the color which we found with GetColor.
7) We click on the stairs to climb down.
8) We wait a bit so the screen has time to load.
9) we exit so it doesn't save thousands of colors, one which is working is enough for the first round.
10) The script finishes.
That is how to do it. the next time the script will come across the stair, it will also search for that color, and because it was there the last time, there is a higher percision chance, and better speed.
Just a little warning: don't go over 25 Integers in an array, because then it would slow the pc down again, so I would suggest something like this:
if GetArrayLength(MyColors) > 20 then
begin
MyColors[0]:=MyColors[20]
MyColors[1]:=MyColors[19]
MyColors[2]:=MyColors[18]
SetArrayLength(MyColors, 3);
end;
the last three will be the best to use, because they were picked the latest, and that way it is likelier that the color changes in rs won't affect it as much, because hte color changes are rather subtle.

[Expansion]
Okay, all this stuff is the dry theory, based upon a boring example, but you know what? I created something interactive, so you can better understand what is happening. Just copy paste this script, and read the instructions on this tut, if the script doesn't explain itself:
program New;
{.include srl/srl.scar}
var
x,y,i,l, mycolor: integer;
mycolors: array of Integer;
begin
repeat
wait(250);
if IsMouseButtonDown(true) then
begin
getMousePos(x,y);
mycolor := GetColor(x,y);
Writeln('Got color '+IntToStr(mycolor)+' on '+IntToStr(x)+'|'+IntToStr(y));
i:=getarraylength(mycolors);
setarraylength(mycolors, i + 1);
MyColors[i]:=myColor;
end;
if IsKeyDown('a') then
for l:=0 to high(MyColors) do
begin
Writeln(IntToStr(MyColors[l])+' is color '+IntToStr(l));
end;
if IsKeyDown('s') then
begin
MyColors[0]:=MyColors[GetArrayLength(MyColors)-1];
MyColors[1]:=MyColors[GetArrayLength(MyColors)-2];
MyColors[2]:=MyColors[GetArrayLength(MyColors)-3];
SetArrayLength(myColors, 3);
for i:=0 to 2 do
begin
Writeln('MyColors['+IntToStr(i)+']='+IntToStr(MyColors[i]));
end;
end;
Until false;
end.
Okay, so what this does is that whenever you click, it adds one Integer to the array, and fills that one in with the color you clicked on. You can review all those colors by simply typing "a". By Typing "s", the first three colors will be replaced with the last three, and then the array will be cut down to the first three colors ([0], [1] and [2]). In this exmaple, switching the colors has no real use, but in a real script, the colors will be more percise in the color finding. But, because this example is not related to color finding at all, it doesn't matter, but it seemed like a good idea to explain what really is going on there. I hope you enjoyed the first expansion to my tutorial [/Expansion]

Well, that was my tutorial, it is up to you to understand the rest, good luck. :)

Feel free to rep me if you think this tutorial is worth a rep point :D

By: Pure1993

BTW: If I made mistakes, please correct me.

EvilChicken!

2008-04-30 17:35:15

program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
MMouse(ColorPointsTPA[i]program DynamicArrayExplanation;x, ColorPointsTPA[i].y, 0, 0); // <---
wait(125);
if IGetUpText='limb-' then
begin
end;
end;
end.

Arrow marks where wrong. Otherwise really good. Add more sections and try to make it slightly more interesting to read, covering all the VERY basic to the more advanced (if it can get more advanced than this.) I feel I've criticized you (constructively) enough, so rep+ for you. Great tut.

Pure1993

2008-05-01 05:23:14

Oh yeah, thanks, i didn't have the time yesterday to read over it, so i didn't cath that, thanks a lot for correcting me :D
Also, thanks for the rep+ :)

Starblaster100

2008-05-01 05:29:40

Right at the end of your tut you have

[php]
if GetArrayLength(MyColors) > 20 then
begin
MyColors[1]:=MyColors[20]
MyColors[1]:=MyColors[19]
MyColors[1]:=MyColors[18]
SetArrayLength(MyColors, 3);
end;
[/php]

which is slighly incorrect (MyColors all have index 1)

Other than that, it looks good :)

Pure1993

2008-05-01 05:31:39

oh yeah, thanks for ironing that one out, the last thing i want to do is confuse teh people who are trying to understand this by making errors myself. Thanks :)

Pure1993

2008-05-01 06:32:18

UPDATED with a new awesome example ;)

Sir R. M8gic1an

2008-05-12 03:27:16

nice tut, although you did not quite grasp Tara's method of chicken killing :p
also tolerance 40 might be a lil bit high?

but as i said, very nice tut, easy to read, easy to understand and teaches a useful technique :)

~RM

Pure1993

2008-05-12 05:52:52

thanks Rm. :)
But, if you think the tol is too high, go ahead and change it in your script, it is quite easy i believe ;)
This is just an example, the first color it find should be the one we are looking for though, at least in this example.
I never read through the entire script from tarajunky, but this isn't hard to find, it uses smart, so just have the script window open for 10 minutes, and check the status bar, and the stuff in the debug box, it is pretty well explained, no need to understand the script… ;)
(also, i think he has a function AddIntoChickenArray or something, that one at least is easy enough ;))

Sir R. M8gic1an

2008-05-13 06:17:06

no need to explain it to me, i use the same method as tarajunky in my scripts :p

~RM

Pure1993

2008-05-13 07:29:48

oh, lol, i understood your post wrong, sorry :p (mistook the "you" for "i" xD)
Well, if i didn't explain it quite right, anyone who would like to know better can just go look at his script, have fun with your headache ;)