Results 1 to 10 of 10

Thread: What are TPointArrays(TPA's) and Some Functions & Procedures to Use 'Em With!

  1. #1
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Cool What are TPointArrays(TPA's) and Some Functions & Procedures to Use 'Em With!

    Hello, welcome to my 5th tut fellow and future scriptures!

    Breaking it Down

    TPoint

    Remember way back in grade 6 math when you had that graph with the x axis and the y axis and the teacher gave you coordinates for points on the graph then asked you to put them in, connect the dots and make a picture of a cat?
    Each of those (x, y) points were known as 'points'. We call them 'TPoints'. Not to hard . For a more technical and shorter definition: "A specified point on the cartesian plane".

    Arrays

    Arrays are a simple way of declaring a bunch of variables that have some similarities. They can be any variables, but the most commonly used are booleans, strings, extendeds and integers. As for an example, here is a simple script i stole from NaumanAkhlaQ's array tut:
    Quote Originally Posted by NaumanAkhlaQ View Post
    SCAR Code:
    Procedure CutTree;
    Var
    YewColor : Array [0..5] of Integer;
    i :Integer;
    Begin
      YewColor[0]:=2182984;
      YewColor[1]:=1855560;
      YewColor[2]:=4426622;
      YewColor[3]:=1914933;
      YewColor[4]:=3239519;
      YewColor[5]:=3116158;
       Begin
     If (not (Loggedin)) then
      Exit;
    else    
      For i:= 0 to 5 do
        If FindObjCustom(x,y,['ew'],[YewColor[i]],5) then
          Begin
            If IsUpText('ew') then
               Begin
                 CutDown;
               end;
          end;
      end;
    Understanding the Use of TPA's

    Now that you understand what a TPoint is, you can also understand that if you use TPoints in a script, and you need multiple TPoints for, lets say, finding an area on the minimap, it would take up a lot of space. It would take up a lot of space because this is how you would give a TPoint a value if you had multiple TPoints, without the use of TPAs:
    SCAR Code:
    program TPointExample;
    var
      Point1, Point2, Point3, Point4, Point5, Point6, Point7, Point8, Point9: TPoint;

    begin
      Point1:= inttopoint(523, 624); //inttopoint is short for integer to point. this takes two integers, in this case an x and a y, and converts it into one TPoint.
      Point2:= inttopoint(253, 734);
      Point3:= inttopoint(954, 736);
      Point4:= inttopoint(1163, 712);
      Point5:= inttopoint(52, 977);
      Point6:= inttopoint(10, 13);
      Point7:= inttopoint(535, 324);
      Point8:= inttopoint(16, 61);
      Point9:= inttopoint(233, 42);
    end.

    Thats alot of text .

    Setting and Finding the Length of a TPA

    First of all, we need to declare the TPA:

    SCAR Code:
    var
      TheTPA: TPointArray;
    Simple as that

    Now here are five procedures/functions that can be used for setting and finding the length of a TPA, I will go into more depth later.

    SCAR Code:
    procedure SetLength(var s; NewLength: Integer);
    procedure SetArrayLength(var Arr; Count: Integer);
    function Length(s): Integer;
    function GetArrayLength(var Arr): Integer;
    function High(x): Int64;

    SetLength: This takes the TPointArray specified (var s), and changes the length to the length specified (NewLength). Heres an example:
    SCAR Code:
    SetLength(TheTPA, 5);
    This will take the TPA 'TheTPA' and change its length to 5.
    SetArrayLength: Very similar to Setlength. It takes the TPointArray specified (var Arr), and changes the length to the length specified (Count). Example:
    SCAR Code:
    SetArrayLength(TheTPA, 5);
    As you can see, it is almost the exact same, except for the procedure title.
    Length: This takes the length of the specified TPA (s) and returns it as an integer. Example:
    SCAR Code:
    var
      TheTPALength: integer;
      TheTPA: TPointArray;

    begin
    TheTPALength := Length(TheTPA);
    WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
    end.
    This finds the length of the TPA 'TheTPA' and stores it as the integer 'TheTPALength', then it transfers the integer into a string and writes the number in the debug box.
    GetArrayLength: This takes the length of the specified TPA (var Arr) and returns it as an integer. Example:
    SCAR Code:
    var
      TheTPALength: integer;
      TheTPA: TPointArray;

    begin
    TheTPALength := GetArrayLength(TheTPA);
    WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
    end.
    This is almost the same thing as Length, except just a different name.
    High: This will find the highest index from out TPA. (e.g., TheTPA[0..10] has a highest index of 10.) Example:
    SCAR Code:
    Writeln('The highest index for TheTPA is ' + inttostr(High(TheTPA)));

    MiddleTPA

    This may sound confusing, but it is really easy once you get it. MiddleTPA finds the exact center of all of your TPA's. NOT the middle number of all your indexes, but the center of all your coordinates. Maybe this will help:

    The x's are your TPoints. The check mark is the exact center of the four TPoints (yes it is, i measured it ).

    Putting it all Togeather

    SCAR Code:
    program TPATogeatherExample;

    var
      TheTPALength: Integer;
      TheTPoint: TPoint;
      TheTPA: TPointArray;

    begin
      SetArrayLength(TheTPA, 6); //TheTPA now has 6 indexes
      TheTPALength := Length(TheTPA); //Giving TheTPA length as the length of TheTPA
      WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
      TheTPA[0]:= inttopoint(613, 834); //Declaring the coordinates...
      TheTPA[1]:= inttopoint(336, 236);
      TheTPA[2]:= inttopoint(723, 443);
      TheTPA[3]:= inttopoint(232, 723);
      TheTPA[4]:= inttopoint(234, 442);
      TheTPA[5]:= inttopoint(633, 666);
      TheTPoint := MiddleTPA(TheTPA); //This declares TheTPoint as the point in the exact center of the other 6 TPoints.
      Writeln('The coordinates of TheTPoint are: (' + inttostr(TheTPoint.x) + ', ' + inttostr(TheTPoint.y) + ').'); //TheTPoint.x is the x coordinate of TheTPoint, same with TheTPoint.y, only with y.
    end.

    Thankyou for reading my first advanced tut. Any questions, comments or corrections, please post below. If you liked my tut, click the blue check mark in the top right corner .
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  2. #2
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Doing well, keep it up.
    Rep+

    T~M

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    where did you get that pick of the barrow tunnels? isnt the minimap black?

    and nice tut too

    and for your arrays,

    SCAR Code:
    TheTPA := [inttopoint(613, 834), inttopoint(336, 236), inttopoint(723, 443)
                 inttopoint(232, 723), inttopoint(234, 442), inttopoint(633, 666)]
    Last edited by Awkwardsaw; 09-21-2009 at 03:52 AM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Shorter way of writing a static TPointArray:

    SCAR Code:
    YourTPA := [Point(454, 676), Point(0, 0), Point(5, 5), ...];

    Edit: Ninja'd, but you edited your post.
    Last edited by Quickmarch; 09-21-2009 at 03:58 AM.
    lol

  5. #5
    Join Date
    Mar 2009
    Location
    Illinois
    Posts
    292
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
    Should be
    SCAR Code:
    WriteLn('The length of TheTPA is ' + inttostr(TheTPALength) + '.');

    Just saying, otherwise very nice!

  6. #6
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    where did you get that pick of the barrow tunnels? isnt the minimap black?

    and nice tut too

    and for your arrays,

    SCAR Code:
    TheTPA := [inttopoint(613, 834), inttopoint(336, 236), inttopoint(723, 443)
                 inttopoint(232, 723), inttopoint(234, 442), inttopoint(633, 666)]
    found the barrows thingy on google images
    i added in the x's and check mark and uploaded on imageshack
    Last edited by Bionicle; 12-01-2009 at 10:37 PM.
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  7. #7
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    N1ce. Keep up the awesome work, you're really active in the community lately .

    I <3 TPAs btw.

    Anyways, add more functions from the wizzy plugin. Such as, SplitTPA, SplitTPAEx which splits the TPointArray, CombineTPA: combines the TPA [sometimes done after splitting it, kinda useful for trees ] Also add MiddleTPAEX, its a boolean so you can use it as a failsafe and doesn't need a TPoint declared. Those are pretty much the most commonly used functions, unless you want to go more in depth and explain aTPA's.

    E = Also include that Length and GetArrayLength do the same thing, but i think GetArrayLength is faster..[might b wrong]. Also assigning an integer to High can be faster since each time you use For i := 0 to High(TPA) do, it becomes slower. You could also do Length(TPA)-1, which does the same thing as High. OMG, why am i explaining all this to you , you probably know this stuff already. [Lol, don't take anything offensive, because some people do when you explain things to them, that i already know ].

    Good job and good luck~

    Last edited by Smarter Child; 09-22-2009 at 07:54 AM.

  8. #8
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice Tutoria l,

    Code:
    procedure SetLength(var s; NewLength: Integer);
    procedure SetArrayLength(var Arr; Count: Integer);
    function Length(s): Integer;
    function GetArrayLength(var Arr): Integer;
    function High(x): Int64;
    In addition to
    Code:
    function High(x): Int64;
    there is also:
    Code:
    function Low(x): Int64;

  9. #9
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by r!ch!e View Post
    Nice Tutoria l,

    Code:
    procedure SetLength(var s; NewLength: Integer);
    procedure SetArrayLength(var Arr; Count: Integer);
    function Length(s): Integer;
    function GetArrayLength(var Arr): Integer;
    function High(x): Int64;
    In addition to
    Code:
    function High(x): Int64;
    there is also:
    Code:
    function Low(x): Int64;
    yea, but i didn't think it was important, as low will always be the same.
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  10. #10
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    I think this belongs to Intermediate section.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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