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