PDA

View Full Version : The Almighty TPA Tutorial



n3ss3s
11-27-2007, 04:58 PM
TPointArrays

In this tutorial, I will teach you how to use TPAs - TPointArrays a.k.a Arrays of TPoint.


Lets start from how to declare a TPointArray.

How to declare a TPoint array

1. Most cool looking and the fastest to type
TPA: TPointArray;

2. The "old" way TPA: Array of TPoint;


With the way 2 you can declare the length of the array when declaring.

Now, you may think that TPointArrays are more complex or harder than other arrays, but thats just figment of your imagination.

Now, lets have a small example:


Procedure TPAExample;
Var
TPA: TPointArray;
Begin
SetArrayLength(TPA, 1);
// Remember that SetArrayLength sets it so that first slot is 0!
TPA[0].x := 10;
TPA[0].y := 5;
Writeln('1.');
Writeln('TPA[0].x = '+IntToStr(TPA[0].x)+'.');
Writeln('TPA[0].y = '+IntToStr(TPA[0].y)+'.');
// Now, another way for setting a point in a TPA
TPA[0] := IntToPoint(10, 5);
Writeln('TPA[0].x = '+IntToStr(TPA[0].x)+'.');
Writeln('TPA[0].y = '+IntToStr(TPA[0].y)+'.');
End;


There you have a TPointArray with one slot, and two ways of setting the point.




Now, you all wonder how to surf through a TPA with your mouse?
Nothing more special than writelning an integer array.



Procedure TPAMouseExample;
Var
TPA: TPointArray;
I, C: Integer;
Begin
SetArrayLength(TPA, 10);
For I := 0 To High(TPA) Do // High = highest slot
Begin
TPA[i].x := (i + 1) * 10;
TPA[i].y := (i + 1) * 20;
End;
// Now, we go through with it using mouse, watch...
For C := 0 To High(TPA) Do
Begin
MoveMouse(TPA[c].x, TPA[c].y);
Wait(250);
End;
End;


Always remember that a point is two integers, X and Y.

Now, you all think "Omfgz0r m003vfmouse d00z not fawnd me objz0r"

FindColorsSpiralTolerance & FindColorsTolerance


The difference between these two wonderful functions is that FindColorsSpiralTolerance searches starting from the two first params, spiralling out.

FindColorsTolerance instead just Finds from X1, Y1 to X2, Y2.

Try messing with this:


Procedure TPAColorExample(StartX, StartY, Color, x1, y1, x2, y2: Integer);
Var
TPA: TPointArray;
I: Integer;
Begin
FindColorsSpiralTolerance(StartX, StartY, TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now, we go through the points found by FindColorsSpiralTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
FindColorsTolerance(TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now we go through the points from FindColorsTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
End;




I gotta stop for today, but don't worry, I'll be back writing this Tut after about 19 hours :)


Cya, hope you learnt something though this session wasn't very long!


-----CONTINUES-----


So, now you know a little, you should be able to make a TPointArray, and do something with the points :)

Multidimensional TPointArrays

Sometimes you may face this feeling that one array just isn't enough, and its
a) Stupid
b) Waste of time
to write like "A1, A2, A3, A4, A5, A6: TPointArray".

Then, just like any other array, you can make a multidimensional array.

For example, you want to find the player pixels of minimap.

You would first do a FindColors with spiral or not to get all the white points.

But now, you have a messy array with points around, you can use that to get the points of the players:) To get the amount of players you can do just like
Players := Round(GetArrayLength(whitePoints) / 9)

Note that the 9 propably isn't the right amount one dot has pixels.

Now, back on topic, now you would want to get the dots.

What do you think you are going to do?

You would (should, IMO) use SplitTPA from WizzyPlugin, or a function of your own that serves the same purpose.

SplitTPA creates a two dimensional array - Array of TPointArray
of one TPointArray, making a TPointArray of each group of points that are next to each other.

Now you would do something like:
PlayerDots := SplitTPA(whitePoints); There you've got your player dots.

But, you can't click a TPointArray, or can you?

Well its kind of how you like to say it, you can click the TPointArray's middle, or the point in middle of the array, or something else.

Well the first option makes most sence, so, you will then have a for loop, and a new TPointArray.

Then you do something like this:


For I := 0 To High(PlayerDots) Do
Try
TheRealDamnPlayerDots[i] := MiddleTPA(PlayerDots[i]);
Except
Writeln('Seems like we had shitty points.');
End;


The try except is because if some array had too low amount of points, our story would end sadly in a runtime error.

I made today early one function for checking the amount of players so the brand new autotalker in my script won't be chatting with JaGeX.

Try to learn something of it :


Function GetPlayers: Integer;
Var
PlayerDots: Array of TPointArray;
WhitePixels: TPointArray;
CTS, X, Y, I: Integer;
Begin
CTS := GetColorToleranceSpeed;
If Not CTS = 2 Then ColorToleranceSpeed(2);
FindColorsTolerance(WhitePixels, 16711422, MMX1, MMY1, MMX2, MMY2, 3);
PlayerDots := SplitTPA(WhitePixels);
For I := 0 To High(PlayerDots) Do
Begin
If GetArrayLength(PlayerDots[i]) > 9 Then
Begin
MiddleTPAEx(PlayerDots[i], X, Y);
If Distance(MMCX, MMCY, X, Y) <= 22 Then
Result := Result + 1;
End;
End;
ColorToleranceSpeed(CTS);
End;


^^ free to use in scripts if I'm being credited.


Simple, isnt it? But even more effective :)



I don't have anything to teach about TPAs in mind atm, but request here if you have something to ask! :)

Cya ppl!

-----------------------------------------------------------------------------------------

Okay, request number one!

Pros and Cons of TPoint Arrays

Pro - Effective
Pro - Fast to make, unlike DDTMs or something like that.
Con - Slow to sort through a TPA and do changes, like any array. (Plugins though)

-----------------------------------------------------------------------------------------

Number two - using TPAs in loops fast.



Number one, don't do
For I := 0 To High(TPA) Do

You can do that, but if you are fighting of milliseconds you need to do


Le := High(TPA);
For I := 0 To Le Do


That ways, it doesn't have to call High every time, and can save you tens of milliseconds.


Then, another thing, since now we have WizzyPlugin in our .Includes/SRL/SRL/Misc/
we should use its functions over your home-made scar ones, unless yours are more effective.

For example, if you first do a FindColors, and then for each point you would like to know how much of color is around it, don't make a loop that does FindColors around each point, instead, just make an Array of TPointArray, and then do like
TPAA := TPAToATPA(TPA, Distance)

Thats propably some of the important things, also common sense will help you.

JuKKa
11-27-2007, 09:20 PM
Ness all im saying is: You're amazing with TPA's ;) A bit too amazing sometimes.

Good tut ;)

King of Knives
11-27-2007, 09:31 PM
I knew you were gonna make one for this :D I'll promise to read :D I need to learn more about them :P I want to beat you :D (Impossible dream)

-Knives

Killerdou
11-27-2007, 09:36 PM
mh, go to the link in my sig and find some more interresting stuff on tpa(its not really explained though but i'm willing to explain on msn...) it also has atpa;) but nice job on the guide it doesnt really belong in the advanced section though...

ZephyrsFury
11-28-2007, 12:53 AM
Goody.... I had to learn this myself :(. Anyways... n3ss3s you still want a tut on trigonometry?

Town
11-28-2007, 01:10 AM
TPointArrays aren't advanced at all, unless you plan on doing something I've never heard of. All you need to know is how to use a TPoint. . . And how to use an array. . . Now that Wizzup made a plugin you don't really have to do anything yourself, you just put in the parameters ;)

Who knows, though, you may know something I don't.

n3ss3s
11-28-2007, 03:54 PM
@Zephyr: I'd love to see one
@Killerdou: Your sig is advertising your finder already
@JuKKa: Thanks
@Town: No, they are simple, but many people have said that z0mg hard etc..

Now, I'm back and continue writing it :stirthepot:

Rikje
11-28-2007, 04:01 PM
i always wanted to know about tpa's. i learned them myself and n3s33s comes with a tut :p

good tut dude :)

Hugolord
11-28-2007, 04:01 PM
can you write pros and cons of em?

n3ss3s
11-28-2007, 04:11 PM
Okay, hold on :)

Okay, added, though don't have more than three in total in my mind atm...

JuKKa
11-28-2007, 04:42 PM
Too bad i had to learn this the hard way.. Teaching my self :(

n3ss3s
11-28-2007, 04:48 PM
Haha, well thats how I learnt it too :)

Though I thought / think of it as fun :p

nielsie95
11-29-2007, 04:20 PM
Nice :)
You could add the optimizing of loops for TPA's..

n3ss3s
11-30-2007, 06:43 AM
Thanks

I'll do it today after school :)

So, now I'm back from school, what do you mean by optimizing?

R0b0t1
11-30-2007, 09:46 PM
Make it faster. Like how you and Ben and all those people were comparing times on the Mining Procedure thread.

n3ss3s
12-01-2007, 07:42 AM
I can't explain it, after all it isn't anything so special...

Umm the one below is propably bit under 100ms, haven't tested... it was 78 or 62 I think.


Function FindRockVein(Var Rx, Ry: Integer; x1, y1, x2, y2: Integer): Boolean;
Var
L, I, Mx, My, P, Col, CTS: Integer;
TPA, TPA2, TPA3: TPointArray;
Box, B2: TBox;
TP: TPoint;
Begin
If Not LoggedIn Then Exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
Box := IntToBox(MSCX - 15, MSCY - 20, MSCX + 15, MSCY + 20);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, RockColor, x1, y1, x2, y2, 15);
L := GetArrayLength(TPA) - 1;
For I := 0 To L Do
Begin
TP := TPA[i];
If(Not(PointInBox(TP, Box)))Then
Begin
FindColorsTolerance(TPA2, MudColor, TP.x - 10, TP.y - 10, TP.x + 10, TP.y + 10, 15);
If(GetArrayLength(TPA2) >= 100)Then
Begin
MiddleTPAEx(TPA2, TP.x, TP.y);
B2 := IntToBox(TP.x - 10, TP.y - 10, TP.x + 10, TP.y + 10);
Mx := B2.x1 + ((B2.x2 - B2.x1) / 2);
My := B2.y1 + ((B2.y2 - B2.y1) / 2);
FindColorsSpiralTolerance(Mx, My, TPA3, RockColor, B2.x1, B2.y1, B2.x2, B2.y2, 15);
If(GetArrayLength(TPA3) >= 25)Then
Begin
P := Round((GetArrayLength(TPA3) / GetArrayLength(TPA2)) * 100);
If(P > 3) And (P < 20)Then
Begin
Result := True;
MiddleTPAEx(TPA3, Rx, Ry);
RockColor := GetColor(TPA3[0].x, TPA3[0].y);
Break;
End;
End;
End;
End;
End;
ColorToleranceSpeed(CTS);
End;


And the one I used in competition, 47ms =

Function FindRock(All: Boolean; var RockTPA: TPointArray; Color: Integer): Boolean;
Var
I, D, C, B, X, Y, A, Z, M, N: Integer;
Var
TPA: TPointArray;
Begin
A := GetClientWindowHandle;
B := GetSystemTime;
C := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
I := BitmapFromString(762, 502, '');
CopyClientToBitmap(i, 0, 0, 762, 502);
SetTargetBitmap(i);
FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2 - 5, MSY2 + 5, 0);
Z := GetArrayLength(TPA);
If(Not(Z <= 0))Then
Begin
For D := 0 To Z - 1 Do
Begin
FastSetPixel(i, TPA[d].x, TPA[d].y, 255);
End;
X := MSX2;
Y := MSY2;
If(Not(All))Then
Begin
If(FindColorSpiral2(X, Y, 255, MSX1, MSY1, MSX2, MSY2))Then
Begin
Result := True;
FindColorsTolerance(TPA, 255, X - 15, Y - 15, X + 15, Y + 15, 0);
SetArrayLength(RockTPA, 1);
RockTPA[0] := MiddleTPA(TPA);
End;
End Else
Begin
FindColorsSpiralTolerance(MSCX, MSCY, RockTPA, 255, MSX1, MSY1, MSX2, MSY2, 0);
If(GetArrayLength(TPA) > 0)Then
Begin
Result := True;
End;
End;
End;
FreeBitmap(i);
SetClientWindowHandle(A);
ColorToleranceSpeed(C);
M := GetSystemTime;
N := M - B;
Writeln(IntToStr(N));
End;


Though I believe I could make better now...

nielsie95
12-01-2007, 09:26 AM
Thanks

I'll do it today after school :)

So, now I'm back from school, what do you mean by optimizing?


Store the arraylength in a variable to speed up loops, do a rangecheck before you do heavier work (in ATPA's). Don't do FindColors twice, like this:


FindColorsTolerance(p, 0, 5, 5, 515, 336, 15);
l := Length(p);
for i := 0 to l -1 do
begin
FindColorsTolerance(tp, 0, p[i].x -5, p[i].y -5, p[i].x +5, p[i].y +5, 15);


IMO it's better to do a TPAtoATPA here.
That's pretty much all I can think of now :p

n3ss3s
12-01-2007, 09:33 AM
Oh, ty, I'll start working on it :)

Negaal
12-15-2007, 04:45 PM
n3s, could you make few examples about object finding...
and examples how to use most used functions from Wizzup's plugin...
and would be cool if you explain all of them : TPoint, TPointArray and Array of TPointArray.

Thank you.

Ok, it may be too much asked...just obj finding... I mean I want to make chicken killer.

Chicken brown colors are hard to seperate from planks and crates and from other same colored stuff...

So what i wanna do is to find chickens red head color, make 30*30 box on it,
and in that box i try to find the brown color center...so far I almost done it, put after few kills i get runtime error, or it won't start at all because of type mismatch...[wrong variables] thats why someone shoud exmplain TPoint, TPointArray and Array of TPointArray.

thx

n3ss3s
12-16-2007, 07:22 PM
Just do a FindColorsSpiralTolerance(RedThing.x - 5, RedThing.y + 8, TehTPA.....)

with the brown color, and then do MiddleTPAEx(TehTPA, ChX, ChY);

WT-Fakawi
12-16-2007, 07:26 PM
Stickyfied.

bullzeye95
12-16-2007, 07:35 PM
Sorry, but I think this should be in Tutorials for Intermediates, BECAUSE there's really not any advanced methods here yet.

But well done tutorial.

n3ss3s
12-16-2007, 07:38 PM
Thanks BullZeye, and yeah, maybe to Intermeds?

Woah, stickied? omg lol, my tut got a sticky xD Thx..

Wanted
12-17-2007, 06:23 PM
Sorry, but I think this should be in Tutorials for Intermediates, BECAUSE there's really not any advanced methods here yet.

But well done tutorial.

Agreed, this is something that shouldn't just be reserved for advanced scripters, because after all, it isn't all that advanced. If you ask me, it should be one of the first things you learn when it comes to finding objects effectively in rs.

Is it effective? Very.
Does it belong in the Advanced Section? No.

Nice tutorial though, N3ss.

bullzeye95
12-18-2007, 01:28 AM
I think you should add stuff like TPA/ATPA size, TPA/ATPA locations, as in middle points related to a point, and mixing TPA/ATPAs, both additive and subtractive. Then I think it would be advanced.

n3ss3s
12-20-2007, 03:29 PM
I have requested for it to be in the beginner or intermediate...

Btw, can the Jrs see only beginner section?

Sir R. M8gic1an
01-20-2008, 07:02 PM
I'm not sure i completly understood SplitTPA. if you use SplitTPA an array will be created from each TPoing the other array had?

so...


ThisTPA[0].x := 20; ThisTPA[0].y := 50;
ThisTPA[1].x := 30; ThisTPA[1].y := 40;
ThisTPA[2].x := 40; ThisTPA[2].y := 30;
ThisTPA[3].x := 50; ThisTPA[3].y := 20;

test:= SplitTPA(thisTPA);

test[0][0].x = 20; ?
test[0][1].x = 0; ?
test[1][0].x = 30; ?
test[1][1].x = 0?
test[1][2].x = 0?


would the test ATPA have the values i showed there?

and waht exactly will MiddleTPA do? it'll analyse all the TPA points and find out the exact middle? so...


ThisTPA[0].x := 0; ThisTPA[0].y := 0;
ThisTPA[1].x := 0; ThisTPA[1].y := 100;
ThisTPA[2].x := 100; ThisTPA[2].y := 0;
ThisTPA[3].x := 100; ThisTPA[3].y := 100;
{100*100 square}
ThisTPoint := MidleTPA(ThisTPA);

ThisTPoint.x = 50?
ThisTPoint.y = 50?


and what the hell does TPAA := TPAToATPA(TPA, Distance) do? I'll make an ATPA with the TPoints of distance x, but how does it know which color we want?

great tut, maybe a few more explained examples?

~RM

n3ss3s
01-20-2008, 07:07 PM
and what the hell does TPAA := TPAToATPA(TPA, Distance) do? I'll make an ATPA with the TPoints of distance x, but how does it know which color we want?


Don't mix TPAs and colors - you get the TPA with the colors you want with FindColorsSpiralTolerance.

TPAToATPA splits a TPointArray to multiple TPointArrays by the areas they are in, like:

Point1-pixel-pixel-pixel-Point2

TPAToATPA(TPA, 3) wouldn't count the Point in because its a "two", only Point1, pixel, pixel would go there.

I think you just overthink it...

and I have no idea wtf were you talking about SplitTPA? SplitTPA(TPA), or nowadays SplitTPA(TPA, 1) puts the points that are connected to eachother to their separate tpas.

Sir R. M8gic1an
01-20-2008, 07:25 PM
Don't mix TPAs and colors - you get the TPA with the colors you want with FindColorsSpiralTolerance.

TPAToATPA splits a TPointArray to multiple TPointArrays by the areas they are in, like:

Point1-pixel-pixel-pixel-Point2

TPAToATPA(TPA, 3) wouldn't count the Point in because its a "two", only Point1, pixel, pixel would go there.

I think you just overthink it...

and I have no idea wtf were you talking about SplitTPA? SplitTPA(TPA), or nowadays SplitTPA(TPA, 1) puts the points that are connected to eachother to their separate tpas.

so in TPAToATPA each point will become a TPA? :) thanks :)

~RM

P1nky
01-20-2008, 10:46 PM
i dont know anythign at all i dont even know what it means

so i would appreciate it if you would like 1st start out by telling what is it for/definition

thanks

Town
01-22-2008, 03:07 AM
i dont know anythign at all i dont even know what it means

so i would appreciate it if you would like 1st start out by telling what is it for/definition

thanks

Is that not what the first line says? If you don't know what a TPoint is then maybe you should start with a beginner tutorial.

n3ss3s
01-22-2008, 03:27 PM
Evil -


Function OgreFound(Var Ox, Oy: Integer): Boolean;
Var
BmX, BmY, R, CTS, I: Integer;
TPAA: Array of TPointArray;
TPA, TPAb: TPointArray;
B: TBox;
Begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
Ox := MSCX;
Oy := MSCY;
FindColorsSpiralTolerance(MSCX, MSCY, TPAb, 8365756, 30, 30, 470, 293, 10);
For I := 0 To High(TPAb) Do
Begin
Ox := TPAb[i].x;
Oy := TPAb[i].y;
B := IntToBox(Ox - 20, Oy - 20, Ox + 20, Oy + 20);
BmX := B.x2 - B.x1 shr 1;
BmY := B.y2 - B.y1 shr 1;
FindColorsSpiralTolerance(BmX, BmY, TPA, 8365756, B.x1, B.y1, B.x2, B.y2, 10);
If GetArrayLength(TPA) > 100 Then
Begin
TPAA := TPAToATPA(TPA, 17);
R := Random(GetArrayLength(TPAA));
SetArrayLength(TPA, GetArrayLength(TPAA[r]));
TPA := TPAA[r];
MiddleTPAEx(TPA, Ox, Oy);
Result := Not(BusyAt(Ox, Oy));
Break;
End;
End;
ColorToleranceSpeed(CTS);
End;


Go to SRL Members Forum -> SRL New Functions and go through until you find
"SCAR code of mine", there is few more.

stampede10343
02-19-2008, 01:08 PM
this and neegal's tutorials helped me a lot thanks

LordGregGreg
04-14-2008, 03:53 PM
Props on the tut, that was a great refresher.

on one of your examples,
"For I := 0 To High(PlayerDots) Do"
did you mean
"For i := 0 To High(PlayerDots) Do"?

ShowerThoughts
04-14-2008, 05:49 PM
Props on the tut, that was a great refresher.

on one of your examples,
"For I := 0 To High(PlayerDots) Do"
did you mean
"For i := 0 To High(PlayerDots) Do"?

what is the diff if it is capital or not?

Thanks N3ss3s i made my first lesser demon finder and it works pretty good :D

Press Play
06-04-2008, 09:00 AM
wat was this --> "Omfgz0r m003vfmouse d00z not fawnd me objz0r"
l0l p10X 0Mg!! =p

very nice tut..short..but detailed..thanx
im going to put it into my miner for V3.0

man slaughter
06-08-2008, 05:42 AM
thanks is not enough, ive been going through these tutorials for a while. among all the tpa tutorials this has been the most helpful. before sitting down and reading the tutorial from top to bottom, i did not know how a tpa could be used to find anything.

now to criticism:
there are a lot of grammatical errors on the tut. its hard to for some including me, to try and deduce what your trying to say.

the only thing i could think of that could be missing is using an array of T2DPA to find areas that have certain colors. im going to embrace this project tomorrow.

n3ss3s
06-08-2008, 09:31 AM
Hehe, I made this some time ago, I think it would be different if I would write one now, but I hope you get atleast a basic understanding...

Only part people actually need to learn there is to learn use an array.

Using a FindColors(Spiral)Tolerance doesn't differ from using any other function, the purpose of it does but like writing the params etc...

If you know how to use an array, which shouldn't be very hard, you won't have much trouble using a 2D -Array either, and then you need only to find functions that fit your purpose...

R0b0t1
07-11-2008, 12:16 AM
I'm afraid I don't get why people make tutorials on how to add '.x' or '.y' to something.


What you should teach is how to use them....

sirlaughsalot
07-11-2008, 12:49 AM
Wow im afraid this stuff is way over my head... Idk why i just dont seem to get it... i really wanna learn it too :(

Claymore
07-12-2008, 06:52 AM
I reccomend u read the TPA made easy guide on the Intermediates section. Otherwise try finding scripts that use these functions and study it. BUT DONT STEAL IT AND SAY ITS YOURS! Your cheating yourself, u lose respect, u know the deal...

Laur€ns
07-16-2008, 11:10 AM
Woo, I'm gonna use this in my Monk Killer + Healer :D *sets bar to 80%*

Yush Dragon
08-13-2010, 12:06 AM
nice tutorial man, helped me to understand some stuff of TPA/ATPA, Thanks!! =D

+Rep

LolL
12-20-2010, 10:35 PM
wow, powerful shit

my own count-the-players-on-the-minimap function (made it for practice and because his seemed a little outdated--calling SplitTPA with only 1 arg?)



function CountPlayers : Integer;
var
WhiteDots : TPointArray;
PlayerDots : T2DPointArray;
SingleDot : TPoint;
I, ArrayHigh : Integer;
begin
if FindColorsTolerance(WhiteDots, 16777215, MMX1, MMY1, MMX2, MMY2, 3) then
begin
PlayerDots := SplitTPA(WhiteDots, 9);
ArrayHigh := High(PlayerDots);
for I := 0 to ArrayHigh do
begin
SingleDot := MiddleTPA(PlayerDots[I]);
MoveMouse(SingleDot.x, SingleDot.y);
Wait(500);
end;
Result := High(PlayerDots) + 1;
end
else
begin
WriteLn('No players found');
Result := 0;
end;
end;


is the if-then necessary or will FindColorsTolerance just return an array with a high of 0?

NCDS
12-20-2010, 10:52 PM
wow, powerful shit

my own count-the-players-on-the-minimap function (made it for practice and because his seemed a little outdated--calling SplitTPA with only 1 arg?)



function CountPlayers : Integer;
var
WhiteDots : TPointArray;
PlayerDots : T2DPointArray;
SingleDot : TPoint;
I, ArrayHigh : Integer;
begin
if FindColorsTolerance(WhiteDots, 16777215, MMX1, MMY1, MMX2, MMY2, 3) then
begin
PlayerDots := SplitTPA(WhiteDots, 9);
ArrayHigh := High(PlayerDots);
for I := 0 to ArrayHigh do
begin
SingleDot := MiddleTPA(PlayerDots[I]);
MoveMouse(SingleDot.x, SingleDot.y);
Wait(500);
end;
Result := High(PlayerDots) + 1;
end
else
begin
WriteLn('No players found');
Result := 0;
end;
end;


is the if-then necessary or will FindColorsTolerance just return an array with a high of 0?

Indeed it would return a length of '0'. Doesn't much matter either way though. :)

XRaye
04-13-2012, 03:12 AM
Great tut, really helped me understand how everything really works instead of just using it and hoping it's right =p

riwu
08-10-2012, 07:52 AM
Number two - using TPAs in loops fast.

Number one, don't do
For I := 0 To High(TPA) Do

You can do that, but if you are fighting of milliseconds you need to do


Le := High(TPA);
For I := 0 To Le Do


That ways, it doesn't have to call High every time, and can save you tens of milliseconds.

Does calling High really take any amount of time? I always thought functions like this would not even take 1 millisecond.

Abu
08-10-2012, 11:17 PM
Does calling High really take any amount of time? I always thought functions like this would not even take 1 millisecond.

I always thought that it did and then some members told me that it didn't, so I officially have no idea.

Having said that, no harm in doing it I guess :p

Nebula
08-10-2012, 11:29 PM
I always thought that it did and then some members told me that it didn't, so I officially have no idea.

Having said that, no harm in doing it I guess :p

Decide for yourself.


Procedure aaa;
var
i, t: Integer;
hhh: Array [0..100] of TPoint;
begin
marktime(t);
for i := 0 to high(hhh) do
// for i := 0 to 100 do
begin
writeln(i);
end;
writeln(TimeFromMark(t));
end;

riwu
08-11-2012, 12:02 AM
Decide for yourself.


Procedure aaa;
var
i, t: Integer;
hhh: Array [0..100] of TPoint;
begin
marktime(t);
for i := 0 to high(hhh) do
// for i := 0 to 100 do
begin
writeln(i);
end;
writeln(TimeFromMark(t));
end;

Yeah that was what i did ytd, there was no observable difference with anything below 100 (empty) loops (both took 0 milliseconds). Just tried again increasing the loop to 10k and there is actually a difference of ~15000 milliseconds in total, of which the increasing difficulty of High functions to count a larger number also attributes to its increasing significance.

So basically dont bother with declaring another variable if your loop is under 100. Not common for a RS script to go over even 20 anyway. (and even if it's at 10k, it will only save u 1.5milliseconds/loop)

Zyt3x
08-11-2012, 12:43 AM
Yeah that was what i did ytd, there was no observable difference with anything below 100 (empty) loops (both took 0 milliseconds). Just tried again increasing the loop to 10k and there is actually a difference of ~15000 milliseconds in total, of which the increasing difficulty of High functions to count a larger number also attributes to its increasing significance.

So basically dont bother with declaring another variable if your loop is under 100. Not common for a RS script to go over even 20 anyway. (and even if it's at 10k, it will only save u 1.5milliseconds/loop)The difference is 0ms if you're using La-pe, though :)

rj
11-27-2012, 01:56 AM
Can't even run examples...

[Error] (1:1): Unexpected end of file at line 0
Compiling failed.

so then i changed it to:
Procedure TPAColorExample(StartX, StartY, Color, x1, y1, x2, y2: Integer);
Var
TPA: TPointArray;
I: Integer;
Begin
FindColorsSpiralTolerance(StartX, StartY, TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now, we go through the points found by FindColorsSpiralTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
FindColorsTolerance(TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now we go through the points from FindColorsTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
End;
begin
procedure TPAColorExample;
End.

[Error] (23:1): Identifier expected at line 22
Compiling failed.

riwu
11-27-2012, 02:02 AM
Can't even run examples...

[Error] (1:1): Unexpected end of file at line 0
Compiling failed.

so then i changed it to:
Procedure TPAColorExample(StartX, StartY, Color, x1, y1, x2, y2: Integer);
Var
TPA: TPointArray;
I: Integer;
Begin
FindColorsSpiralTolerance(StartX, StartY, TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now, we go through the points found by FindColorsSpiralTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
FindColorsTolerance(TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now we go through the points from FindColorsTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
End;
begin
procedure TPAColorExample;
End.

[Error] (23:1): Identifier expected at line 22
Compiling failed.

When you call a procedure, just call the name:

begin
TPAColorExample;
end.

Spartan 117
03-01-2013, 03:41 PM
I find this concept soo confusing. Maybe some examples of how to actually use in rs besides the players such as object finding!

kakadudl
11-02-2015, 09:26 PM
Wow thanks for this simple tutorial! It's helping me a lot when finding objects for my script.