PDA

View Full Version : TPointArrays: Explained[TPAs]



NKN
06-18-2012, 03:08 PM
Contents

Introductions
Variables

Arrays
TPoint

Base Code
SplitTPA
Finishing Touches
Conclusion


Introductions
Hey guys, this is the latest installment of my Explained tutorial series.
We're going to step your way through TPA object finding. It can later be combined with Autocoloring, but you can do that later. :P
Without further ado, let's get started.

Variables
A TPA stands for TPointArray, or an Array Of TPoint. It can be shown like this:

ArrayNameHere:TPointArray;

or the old fashioned way:

ArrayNameHere:Array Of TPoint;



Arrays
Now wait.... what's a Array! Glad you asked. Think of a variable as a cookie(We all love cookies, right?) A variable is one single cookie, and the array is the cookie box. It can hold multiple cookies! So, basically, an array can just "hold" multiple variables. (They have to be the same type! Can't mix strings and variables with em!) Got it?
TL;DR(or summary) An Array can hold multiple of one type of variable.

TPoint
Now that you got that, what are TPoints! Well, let me explain.

NameHere:TPoint;
NameHere := Point(500,500);

A TPoint holds x,y variables. X being the first one, Y being the second. It's used for things like Mouse(x,y,4,4,1);
You assign a TPoint by using
Point(-numberhere-,-numberhere-)
// Or You can use:
Point(x,y);
//You can use x,y if something fills x,y, such as FindColorTolerance
As you can see,a TPointArray is just multiple TPoints, or variables of x,y.

Base Code
Alright, time to get to the nitty gritty. You're probably shaking in your seats, unable to contain that excitement, right? I'll go over everything in detail after the code.

Function FunctionNameHere(var x,y:integer) : Boolean;
var
Ax, Ay : Integer; //Just a place to store our variables.
TPA : Array Of TPoint;//Our original TPA
ATPA : T2DPointArray; //This is going to be our split TPA
i : Integer; // We use this in our For loop. :D

begin
FindColorsSpiralTolerance(Ax, Ay, TPA, -colorhere-, MSX1, MSY1, MSX2, MSY2, -tolerance here-)
begin
ATPA := SplitTPA(TPA, 10);
for i := 0 To High(ATPA) Do
begin
if MiddleTPAEX(ATPA[i], Ax, Ay) then
MMouse(Ax, Ay, 1, 1);
if IsUpText('-uptext here-') Then
begin
x := Ax;
y := Ay;
Writeln('Got it');
Result := True;
end;
Exit;
end;
end;
end;
Alright, let's get started!

Function FunctionNameHere(var x,y:integer) : Boolean;

Here's the name, it returns a variable(Boolean in this case.)
It also returns x,y, so you can use it differently. I'll show you in the later chapters.

var
Ax, Ay : Integer; //Just a place to store our variables.
TPA : Array Of TPoint;//Our original TPA
ATPA : T2DPointArray; //This is going to be our split TPA
i : Integer; // We use this in our For loop. :D
Ax,Ay, this is where we store our x,y values in
TPA is the name of the TPointArray we're going to make
ATPA is the name of the split TPA. (An array of an array, so a container that contains containers. :D)
i is used for the for loop

begin
FindColorsSpiralTolerance(Ax, Ay, TPA, -colorhere-, MSX1, MSY1, MSX2, MSY2, -tolerance here-)
Note the S after color. This is so it stores multiple points in a TPA, which is why we wrote TPA.

begin
ATPA := SplitTPA(TPA, 10);
for i := 0 To High(ATPA) Do
if MiddleTPAEX(ATPA[i], Ax, Ay) then
MMouse(Ax, Ay, 1, 1);
Now, ATPA happens when we split our TPA. I'll explain that in detail in the next chapter.
Our For Loop just runs through every point in the 2DTPA, ATPA.
The if line, moves us to the middle of the TPA, so the middle of what ever color we find, useful so we're not clicking edges.
MMouse moves the mouse to that position, and just sits there for the next part.

if WaitUpText('-uptext here-',400) Then
begin
x := Ax;
y := Ay;
Writeln('Got it');
Result := True;
end;
Exit;
end;
end;
After we moved the mouse, it waits for the uptext we specified for 400 milliseconds. If it has that, it sets x,y to Ax,and Ay, then function returns true, and the debug box writes "Got it.", just so we know if it found it or not.


SplitTPA

function SplitTPA(const arr: TPointArray; Dist: Integer): T2DPointArray;
What SpitTPA does, is it looks for points close together. The search radius is made bigger or smaller by changing the number of Dist.(Which is the second thing you put in when you call SplitTPA.) It groups them together, and then returns it as a T2DPointArray. Now, if there are multiple of these groups, and they overlap each other,(The edge of one groups, overlaps the edge of another one), it just adds them together, and makes one big shape.

SplitTPA isn't the only one you can use, there are multiple functions that join TPoints. Head over to WizzyPlugins and read about all of those for a more detailed list.

Hope that cleared some of the confusion of what SplitTPA does.

Finishing Touches

Function FunctionNameHere(var x,y:integer) : Boolean;
var
Ax, Ay : Integer; //Just a place to store our variables.
TPA : Array Of TPoint;//Our original TPA
ATPA : T2DPointArray; //This is going to be our split TPA
i : Integer; // We use this in our For loop. :D

begin
FindColorsSpiralTolerance(Ax, Ay, TPA, -colorhere-, MSX1, MSY1, MSX2, MSY2, -tolerance here-)
begin
ATPA := SplitTPA(TPA, 10);
for i := 0 To High(ATPA) Do
begin
if MiddleTPAEX(ATPA[i], Ax, Ay) then
MMouse(Ax, Ay, 1, 1);
if IsUpText('-uptext here-') Then
begin
x := Ax;
y := Ay;
Writeln('Got it');
Result := True;
end;
Exit;
end;
end;
end;
begin
procedure FindTheThing;
var
x,y:integer;
begin
if(FindTheItems(x,y)) then
begin
Mouse(x,y,1,1,1);
Writeln('Got it!');
end;
end;
begin
FindTheThing;
end.
And there we have it!

if(FindTheItems(x,y)) then
begin
Clickmouse2(1);
Writeln('Got it!');
end;
It takes the returned x,y from FindTheItems, moves the mouse, and clicks, picking the item up. It then writes Got It! when finished.


Conclusion
Thanks for reading guys, if you have any questions PM me, or leave a comment below. Any suggestions, same rules as above apply, and I'll try to implement them as soon as possible.

Sin
06-18-2012, 03:15 PM
Flubbered up here pal.

Function FunctionNameHere(var x,y:integer) : Boolean;
var
Ax, Ay : Integer; //Just a place to store our variables.
TPA : Array Of TPoint;//Our original TPA
ATPA : T2DPointArray; //This is going to be our split TPA
i : Integer; // We use this in our For loop. :D

begin
FindColorsSpiralTolerance(Ax, Ay, TPA, -colorhere-, MSX1, MSY1, MSX2, MSY2, -tolerance here-)
begin
ATPA := SplitTPA(TPA, 10);
for i := 0 To High(ATPA) Do
if MiddleTPAEX(ATPA[i], Ax, Ay) then
MMouse(Ax, Ay, 1, 1);
if IsUpText('-uptext here-') Then
begin
x := Ax;
y := Ay;
Writeln('Got it');
Result := True;
end;
Exit;
end;
end;
begin
procedure FindTheThing;
var
x,y:integer;
begin
if(FindTheItems(x,y)) then
begin
Mouse(x,y,1,1,1);
Writeln('Got it!');
end;
end;
begin
FindTheThing;
end.

You're making the mouse move to the object, then moving to click it again :p

NKN
06-18-2012, 03:34 PM
That's how I usually do it in my scripts. I should change that then. xD

Sin
06-18-2012, 03:36 PM
It's not bad, just bad in practice.
It makes the mouse really jumpy.

Ashaman88
06-18-2012, 03:52 PM
It's not bad, just bad in practice.
It makes the mouse really jumpy.
+1

Also you might want to mention that splittpa is just one of many functions that can be used and that there are some cases where splittpa isn't the best method. But overall nice guide!

Abu
06-18-2012, 03:53 PM
Here is an example you can use to differentiate TPoints and TPointArrays

A TPoint (x and y) would return:

http://img836.imageshack.us/img836/8584/tpoint.png

A TPA (TPointArray) would return:

http://img822.imageshack.us/img822/9931/tpointarray.png

Footy
08-14-2012, 02:12 PM
Isnt there supposed to be a begin after the for..to..do statement? I tried making this withount the begin, and it just flailed the mouse around my TPA like crazy.

Brandon
08-14-2012, 02:14 PM
Isnt there supposed to be a begin after the for..to..do statement? I tried making this withount the begin, and it just flailed the mouse around my TPA like crazy.

You only need begin's and end's for multiple line sequences:


if (.....) then
....... //only one line..



if (.......) then
begin //Multiple lines to be executed "IF condition"
........
,,,,,,,,
*****
end;

Footy
08-14-2012, 02:16 PM
hmm, i must be missing something then...

for i := 0 To High(ATPA) Do
if MiddleTPAEX(ATPA[i], Ax, Ay) then
MMouse(Ax, Ay, 1, 1);
if IsUpText('-uptext here-') Then
begin
x := Ax;
y := Ay;
Writeln('Got it');
Result := True;
end;
This go through your TPA in the for..to..do statement, and move the mouse, but thats it, right? Because after it moves the mouse, it does the for..to..do statement again... Atleast thats what happened when I was testing my ATPA.

Brandon
08-14-2012, 02:19 PM
Because you're telling it to only execute this:

if MiddleTPAEX(ATPA[i], Ax, Ay) thenMMouse(Ax, Ay, 1, 1);

Every for loop. it should have a begin and end before the MMouse and one to match respectively.

Footy
08-14-2012, 02:26 PM
I think thats what I was suggesting in my first post, because in the OP, there is no begin.

NKN
08-14-2012, 04:49 PM
Hurrr, I derped.

Zeta Matt
09-08-2013, 03:37 PM
Great tutorial, was very good for getting a general knowledge on what the hell TPA was :) Moving to a tutorial that teaches about more TPA functions o/

milo11
11-01-2013, 09:56 PM
still confused on TPA/SplitTPA especially. :(
btw what's High(ATPA)?

NKN
11-01-2013, 10:04 PM
still confused on TPA/SplitTPA especially. :(
btw what's High(ATPA)?

High(TPA) is returning the amount of elements in said PA.

TPA is a collection of points, and SplitTPA turns one large collection of points, into multiple, but smaller, collection of points.

masterBB
11-01-2013, 10:07 PM
still confused on TPA/SplitTPA especially. :(
btw what's High(ATPA)?

A TPA is just a list of points. Let's take a tpa called someTPA.

var
someTPA: TPointArray;

...

SetLength(someTPA, 5);
someTPA[0] := Point(3, 5);
someTPA[1] := Point(8, -3);
someTPA[2] := Point(4, 4);
someTPA[3] := Point(6, 7);
someTPA[4] := Point(1, 9);


So someTPA[0] is the first point from the list someTPA[2] is the third point etc etc. Length(someTPA); will return the amount of points stored in the array(list), which will return 5 in this case. High(someTPA); will return the highest index from the array, in this case 4. Note it will be always length - 1.

So if you understand that, image a list of list. In code that is an array of array. Every index from the array contains another array. Indexes in that second array will return the points.

var
someATPA;

...

SetLength(someATPA, 3);
someATPA[0] := inventoryTPA;
someATPA[1] := someTPA;
someATPA[2] := FindColors(params);

High(someATPA) would return 2. Length(someATPA) would return 3. Let's say that someTPA is the TPA from my previous example: someATPA[1] == someTPA. Which means Length(someATPA[1]); would return 5! and someATPA[1][3] would return Point(6, 7).

milo11
11-02-2013, 09:59 AM
A TPA is just a list of points. Let's take a tpa called someTPA.

var
someTPA: TPointArray;

...

SetLength(someTPA, 5);
someTPA[0] := Point(3, 5);
someTPA[1] := Point(8, -3);
someTPA[2] := Point(4, 4);
someTPA[3] := Point(6, 7);
someTPA[4] := Point(1, 9);


So someTPA[0] is the first point from the list someTPA[2] is the third point etc etc. Length(someTPA); will return the amount of points stored in the array(list), which will return 5 in this case. High(someTPA); will return the highest index from the array, in this case 4. Note it will be always length - 1.

So if you understand that, image a list of list. In code that is an array of array. Every index from the array contains another array. Indexes in that second array will return the points.

var
someATPA;

...

SetLength(someATPA, 3);
someATPA[0] := inventoryTPA;
someATPA[1] := someTPA;
someATPA[2] := FindColors(params);

High(someATPA) would return 2. Length(someATPA) would return 3. Let's say that someTPA is the TPA from my previous example: someATPA[1] == someTPA. Which means Length(someATPA[1]); would return 5! and someATPA[1][3] would return Point(6, 7).

that cleared a lot, thank you will +1 if I can.
but what are TPA's/splitTPAs useful for?


High(TPA) is returning the amount of elements in said PA.

TPA is a collection of points, and SplitTPA turns one large collection of points, into multiple, but smaller, collection of points.

arite ;)
will +rep for your tut, thanks :)