Results 1 to 17 of 17

Thread: TPointArrays: Explained[TPAs]

  1. #1
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default TPointArrays: Explained[TPAs]

    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:
    Simba Code:
    ArrayNameHere:TPointArray;
    or the old fashioned way:
    Simba Code:
    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.
    Simba Code:
    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
    Simba Code:
    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.
    Simba 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!
    Simba Code:
    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.
    Simba Code:
    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. )
    i is used for the for loop
    Simba Code:
    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.
    Simba Code:
    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.
    Simba Code:
    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

    Simba Code:
    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

    Simba 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;
    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!
    Simba Code:
    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.
    Last edited by NKN; 08-14-2012 at 04:51 PM. Reason: I herpdaderped

  2. #2
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Flubbered up here pal.
    Simba 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
            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

  3. #3
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    That's how I usually do it in my scripts. I should change that then. xD

  4. #4
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    It's not bad, just bad in practice.
    It makes the mouse really jumpy.

  5. #5
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by Shay View Post
    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!

  6. #6
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Here is an example you can use to differentiate TPoints and TPointArrays

    A TPoint (x and y) would return:



    A TPA (TPointArray) would return:

    Last edited by Abu; 06-18-2012 at 04:04 PM.

  7. #7
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Footy View Post
    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:

    Simba Code:
    if (.....) then
         .......       //only one line..

    Simba Code:
    if (.......) then
    begin        //Multiple lines to be executed "IF condition"
       ........
       ,,,,,,,,
       *****
    end;
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    hmm, i must be missing something then...
    Simba Code:
    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.
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  10. #10
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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.
    I am Ggzz..
    Hackintosher

  11. #11
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I think thats what I was suggesting in my first post, because in the OP, there is no begin.
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  12. #12
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Hurrr, I derped.

  13. #13
    Join Date
    May 2012
    Location
    Brazil, Rio de Janeiro.
    Posts
    160
    Mentioned
    2 Post(s)
    Quoted
    32 Post(s)

    Default

    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/

  14. #14
    Join Date
    Feb 2012
    Posts
    27
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    still confused on TPA/SplitTPA especially.
    btw what's High(ATPA)?

  15. #15
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by milo11 View Post
    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.

  16. #16
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by milo11 View Post
    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).
    Working on: Tithe Farmer

  17. #17
    Join Date
    Feb 2012
    Posts
    27
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    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?

    Quote Originally Posted by NKN View Post
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •