Results 1 to 11 of 11

Thread: what to set, to prevent out of range?

  1. #1
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default what to set, to prevent out of range?

    I can use this function I made, sometimes - once. Then it will highlight or automatically highlight an out of range error, but I can't seem to see the reason/var I need to limit?

    The function is suppose to find the given input colors (preferabbly all/all but 1) within a 50x50 ATPA of the TPA(mainscreen). Then that box becomes the result, and we'll click there.

    example:
    Simba Code:
    {$include SRL\SRL.simba}

    function a_Bank(colors:tintegerarray; tries, tol: integer): boolean;
    var
      count, lala, i: integer;
      bankerTPA: TPointArray;
      The_Banker_Box_50_x_50: T2DPointArray;
    begin
      result := false;
      if not loggedin then
        exit;
      lala := Length(colors);
      for count := 1 to high(tries - 1) do
      begin
        for i := 0 to high(lala) do
          if findcolorstolerance(bankerTPA, colors[i], msx1, msy1, msx2, msy2, tol) then
          // Out of Range @ this line above ^^^
          begin
            SortATPAFrom(The_Banker_Box_50_x_50, Point(MSCX, MSCY));
            SplitTPAWrap(bankerTPA, 50, The_Banker_Box_50_x_50);
            if TPAInATPA(bankerTPA, The_Banker_Box_50_x_50, i) then
            begin
              mouse(The_Banker_Box_50_x_50[i][i].x, The_Banker_Box_50_x_50[i][i].y, 5, 5, mouse_right);
              result := waitoption('nk Ba', 1000);
              exit;
            end;
          end;
        if count >= tries then
          exit;
      end;
    end;

    begin
      SetupSRL;
      a_Bank([14474983, 7576783, 5059387, 6505035, 3230297], 5, 5);
    end.

    Any help on this would be much appreciated!

  2. #2
    Join Date
    Apr 2007
    Posts
    373
    Mentioned
    2 Post(s)
    Quoted
    24 Post(s)

    Default

    if findcolorstolerance(bankerTPA, colors[i], msx1, msy1, msx2, msy2, tol) then

    That is the reason of the error.
    To solve it u must do this

    Simba Code:
    lala := Length(colors);
    ->
    Simba Code:
    lala := High(colors);

    let me know how it goes
    ~Fre

  3. #3
    Join Date
    Mar 2012
    Location
    Canada
    Posts
    870
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Obviously it's the variable Colors that is causing the out of range.

    You are also doing some wierd stuff with 'lala'. Not a great name for a variable either.

    Simba Code:
    {$include SRL\SRL.simba}

    function a_Bank(colors:tintegerarray; tries, tol: integer): boolean;
    var
      count, lala, i: integer;
      bankerTPA: TPointArray;
      The_Banker_Box_50_x_50: T2DPointArray;
    begin
      result := false;
      if not loggedin then
        exit;
      lala :=high(colors);
      for count := 1 to high(tries - 1) do
      begin
        for i := 0 to lala do
          if findcolorstolerance(bankerTPA, colors[i], msx1, msy1, msx2, msy2, tol) then
          begin
            SortATPAFrom(The_Banker_Box_50_x_50, Point(MSCX, MSCY));
            SplitTPAWrap(bankerTPA, 50, The_Banker_Box_50_x_50);
            if TPAInATPA(bankerTPA, The_Banker_Box_50_x_50, i) then
            begin
              mouse(The_Banker_Box_50_x_50[i][i].x, The_Banker_Box_50_x_50[i][i].y, 5, 5, mouse_right);
              result := waitoption('nk Ba', 1000);
              exit;
            end;
          end;
        if count >= tries then
          exit;
      end;
    end;

    begin
      SetupSRL;
    My scripts:
    Advanced Barb Agility Course(outdated), MonkeyThieverV0.11, MahoganyTableV0.4(outdated)
    Questions? I bet that for 98% of those, you'll find answer HERE

  4. #4
    Join Date
    Apr 2007
    Posts
    373
    Mentioned
    2 Post(s)
    Quoted
    24 Post(s)

    Default

    Do you know the difference between Lenght and High?
    It is an important difference, lookup a small tut about it.
    Espacially for loops you must know the difference.

    If you can't find any tut about it, let me know here and i ll explain.
    ~Fre

  5. #5
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Oh thanks! Works like a charm now >.< I don't/didn't know the difference, really at all, before this. I used Google and got some cool information, more than I was expecting. For example, the difference between categorical, ordinance, and interval variables (here). I also found a tutorial relative to distinguishing the differences from length (here) to high.

    So from what I understand, Length() would return how many variables are being measured, and high() would return the largest/highest variables being measured? I suppose this is why my code messed up, as I looked up until the length of 'lala' instead the highest count of 'lala'?
    So...
    Simba Code:
    var
      arr: TIntegerArray;
    begin
      x := [5, 6, 7, 2, 7, 9];
      Length(arr); //6. B/c there are 6 integers within the array, right?
      High(arr); //9. B/c we're grabbing the highest possible integer within arr?
    end.
    Thanks all for the feedback, helped me a lot!

  6. #6
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    So from what I understand, Length() would return how many variables are being measured, and high() would return the largest/highest variables being measured? I suppose this is why my code messed up, as I looked up until the length of 'lala' instead the highest count of 'lala'?
    So...
    Simba Code:
    var
      arr: TIntegerArray;
    begin
      x := [5, 6, 7, 2, 7, 9];
      Length(arr); //6. B/c there are 6 integers within the array, right?
      High(arr); //9. B/c we're grabbing the highest possible integer within arr?
    end.
    Thanks all for the feedback, helped me a lot!
    Close, but not quite

    High() returns the location of the last stored value, and Length() returns the number of stored values. Since arrays start at 0, the length is always (I think?!..?) 1 greater than the high of an array.

    For example:

    Simba Code:
    var
      Arr: TIntegerArray;

    Arr := [1, 5, 3, 2];

    High(Arr) would be 3 since Arr[3] is the location of the last stored integer.
    Length(Arr) would be 4 since the array has 4 values.

    So they are pretty much interchangeable since:

    Code:
    High(Arr) = Length(Arr) - 1
    Length(Arr) = High(Arr) + 1
    Hope that clears things up
    Last edited by Runaway; 08-14-2012 at 11:50 PM.

  7. #7
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    How come the last stored integer isn't 2?
    Is it the second to last integer in the array or is there something I'm missing blindly?
    Or is it that the last stored integer is technically 3, not 2?

  8. #8
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    High returns then Length of the array - 1, and length returns the length of the array.
    so if a array had 11 elements then length would return 11, and high would return 10 :P
    Edit: basically what runaway said in simpler terms i guess?

  9. #9
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Runaway
    location of the last stored integer
    The keyword is location. High() returns the location, relative to the array, of the last stored value. So if you do:

    Simba Code:
    Arr := [1, 2, 3];
    // or
    Arr := [0, 1, 2, 3];
    // or
    Arr := [-1, 0, 1, 2, 3];

    Writeln(Arr[High(Arr)]);

    It will debug 3 every time since High(Arr) returns 2, 3 and 4 respectively. Here's a little table to simplify things:

    Code:
    Array: [1, 2, 3]
    High(Array): 2
    Array[High(Array)]: 3
    
    Array: [5, 14, 2, 8]
    High(Array): 3
    Array[High(Array)]: 8
    
    Array: [0, 1, 11, 3, 6]
    High(Array): 4
    Array[High(Array)]: 6
    Just compare the relationship between those 3 example arrays and I think you'll understand as fully as possible
    Last edited by Runaway; 08-15-2012 at 12:14 AM.

  10. #10
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Oh that makes a lot more sense now. I thought at first, that the indexed number in the array was the second to last / the result of High(); So I now know that High(); takes the count of the array - 1. Then length does simply the entire count of the array, right?

  11. #11
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    Oh that makes a lot more sense now. I thought at first, that the indexed number in the array was the second to last / the result of High(); So I now know that High(); takes the count of the array - 1. Then length does simply the entire count of the array, right?
    Exactly. If arrays started at 1 instead of 0, then High() and Length() would always be the same.

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
  •