Results 1 to 15 of 15

Thread: Out Of Range

  1. #1
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Out Of Range

    SCAR Code:
    Wait(1500);
       FindColorsSpiralTolerance(Round(259.5), Round(170.5), TPA, RockAutoColor, MSX1, MSY1, MSX2, MSY2, 15);
       FilterPointsPie(TPA, 0, 360, 0, 170, Round(259.5), Round(170.5));

       ATPA := TPAToATPA(TPA, 21);
       SortATPAFromFirstPoint(ATPA, PointFinder);

       For I := 0 To High(ATPA) Do
       Begin
         TB[J] := GetTPABounds(ATPA[I]);  //<----- Here ----
         DebugATPABound(TB, '');
         For J := 0 To High(TB) DO
         Begin
           If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
           Begin
             MX :=  (TB[J].X1 + TB[J].X2)/2;
             MY :=  (TB[J].Y1 + TB[J].Y2)/2;
             MineIt := False;
             WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
           End;
         End;
       End;
    Out OF Range Error, Now What i would like from u fellows is a detailed Explanation of this

  2. #2
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I would say you haven't set the length of TB properly or assigned J properly (think it's more likely the latter), so the TB[J] is throwing the out of range error. As you don't reset J in the loop, upon second loop through (of the for I loop) J would have the value High(TB) + 1, which is what would throw it I believe.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

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

    Default

    you should also add this before to prevent errors:
    Code:
    if Length(ATPA) = 0 then Exit; // Or you could use a failsafe here.

  4. #4
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I Did this :
    SCAR Code:
    SetLength(TB, GetArrayLength(ATPA));
    and it still out of ranged but this time i think during the loop, Explanation please

  5. #5
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nevermind, I fail. At school, not really looking it over xD.

    ~Sandstorm
    Last edited by Sandstorm; 09-09-2009 at 10:42 PM.

  6. #6
    Join Date
    Jan 2008
    Location
    Frankfurt, Germany
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mixster View Post
    I would say you haven't set the length of TB properly or assigned J properly (think it's more likely the latter), so the TB[J] is throwing the out of range error. As you don't reset J in the loop, upon second loop through (of the for I loop) J would have the value High(TB) + 1, which is what would throw it I believe.
    Quote Originally Posted by hackncrack1 View Post
    SCAR Code:
    Wait(1500);
       FindColorsSpiralTolerance(Round(259.5), Round(170.5), TPA, RockAutoColor, MSX1, MSY1, MSX2, MSY2, 15);
       FilterPointsPie(TPA, 0, 360, 0, 170, Round(259.5), Round(170.5));

       ATPA := TPAToATPA(TPA, 21);
       SortATPAFromFirstPoint(ATPA, PointFinder);

       For I := 0 To High(ATPA) Do
       Begin
         TB[J] := GetTPABounds(ATPA[I]);  //<----- Here ----
         DebugATPABound(TB, '');
         For J := 0 To High(TB) DO
         Begin
           If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
           Begin
             MX :=  (TB[J].X1 + TB[J].X2)/2;
             MY :=  (TB[J].Y1 + TB[J].Y2)/2;
             MineIt := False;
             WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
           End;
         End;
       End;
    Out OF Range Error, Now What i would like from u fellows is a detailed Explanation of this
    SCAR Code:
    Wait(1500);
       FindColorsSpiralTolerance(Round(259.5), Round(170.5), TPA, RockAutoColor, MSX1, MSY1, MSX2, MSY2, 15);
       FilterPointsPie(TPA, 0, 360, 0, 170, Round(259.5), Round(170.5));

       ATPA := TPAToATPA(TPA, 21);
       SortATPAFromFirstPoint(ATPA, PointFinder);
       SetArrayLength( TB, Length(ATPA)); // <---- Here -----
       For I := 0 To High(ATPA) Do
       Begin
         TB[I] := GetTPABounds(ATPA[I]);  //<----- And Here ----
         DebugATPABound(TB, '');
         For J := 0 To High(TB) DO
         Begin
           If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
           Begin
             MX :=  (TB[J].X1 + TB[J].X2)/2;
             MY :=  (TB[J].Y1 + TB[J].Y2)/2;
             MineIt := False;
             WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
           End;
         End;
       End;

    Jus to clarify, that is one of the two options mixster meant, I belive. ^^

    The problem is probably that (as mixster has already said) the length of TB hasn't been defined... an array needs to be given a length before you can use it.... hope it helped.
    (All credit goes to mixster, I only tried to make it a bit easier to understand )
    There is nothing right in my left brain and there is nothing left in my right brain.

  7. #7
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Pure Thanks For ur time but i fixed it but i got in the debug like 10 points per box any help?
    Code:
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 212,140 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 281,108 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 317,134 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 284,79 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 315,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False
    Found Iron Ore At 350,107 Mine It = False

  8. #8
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    You might want to sort the TPAs from MSCX, MSCY by using SortTPAFromFirstPoint ;
    You might also want to use MiddleTPA. Middle TPA will return you one single point in the middle of the TPA.

    The reason why you get ten (equal) points per TPA is cus you sort of did your own custom MiddleTPA and you loop through your TPA with the changed values, Rather than looping through your ATPA.
    SCAR Code:
    For J := 0 To High(TB) DO
         Begin
           If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
           Begin
             MX :=  (TB[J].X1 + TB[J].X2)/2;
             MY :=  (TB[J].Y1 + TB[J].Y2)/2;
             MineIt := False;
             WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
           End;
         End;

    //change to
           If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
           Begin
             MX :=  (TB[J].X1 + TB[J].X2)/2;
             MY :=  (TB[J].Y1 + TB[J].Y2)/2;
             MineIt := False;
             WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
           End;

    ~RM
    Last edited by Sir R. M8gic1an; 09-09-2009 at 11:14 PM.

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  9. #9
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Rasta i dont get what u changed and it has to be ATPA for my application but here is the script after i fixed out of range
    SCAR Code:
    SetLength(TB, GetArrayLength(ATPA));
       For I := 0 To High(ATPA) Do
       For J := 0 To High(TB) DO
       Begin
         TB[J] := GetTPABounds(ATPA[I]);
         If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
         Begin
           MX :=  (TB[J].X1 + TB[J].X2)/2;
           MY :=  (TB[J].Y1 + TB[J].Y2)/2;
           MineIt := False;
           WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
         End;
       End;

  10. #10
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Remove the "For J := 0 to High(TB) DO" then change references of TB[J] to TB[I].
    As you haven't set all values of TB, looping through all of them all will mean that at the beginning near all of them will be default TBox's and then after you have set them, they will be run through again and again when 'I' increases.
    I believe you could probably also get away with only using a TBox instead of an array of TBox unless you plan on saving all the points where the Iron Ore is found. Also, I would say you want to break/exit after finding the Iron Ore, but not sure without more of the script.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  11. #11
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    As you haven't set all values of TB
    Haven't i done that by doing
    SCAR Code:
    SetLength(TB, GetArrayLength(ATPA));
    ?
    The Whole Function is
    SCAR Code:
    Procedure Mining;

    Var
      I, J, X, Y, MX, MY : Integer;
      TPA : TPointArray;
      ATPA : T2DPointArray;
      TB : Array Of TBox;
      MineIt : Boolean;
     
    Begin

       Wait(1500);
       FindColorsSpiralTolerance(Round(259.5), Round(170.5), TPA, RockAutoColor, MSX1, MSY1, MSX2, MSY2, 15);
       FilterPointsPie(TPA, 0, 360, 0, 170, Round(259.5), Round(170.5));

       ATPA := TPAToATPA(TPA, 21);
       SortATPAFromFirstPoint(ATPA, PointFinder);

       SetLength(TB, GetArrayLength(ATPA));
       For I := 0 To High(ATPA) Do
       For J := 0 To High(TB) DO
       Begin
         TB[J] := GetTPABounds(ATPA[I]);
         If FindColorTolerance(X, Y, 4217972, TB[J].X1, TB[J].Y1, TB[J].X2, TB[J].Y2, 15) Then
         Begin
           MX :=  (TB[J].X1 + TB[J].X2)/2;
           MY :=  (TB[J].Y1 + TB[J].Y2)/2;
           MineIt := False;
           WriteLn('Found Iron Ore At ' + IntToStr(MX) + ',' + IntToStr(MY) + ' Mine It = ' + BoolToStr(MineIt));
         End;
       End;
       
    End;

  12. #12
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I was probably not too clear.
    You have set the length of them, but you then go and assign them all to the same, default value of 'GetTPABounds(ATPA[i]);'. You loop through all of TB, but assign it the same value, so it checks the same box multiple times.
    Also, if that's the entire procedure, then you don't really need to have TB as an array - you can just use the same TBox every time and set its value to 'GetTPABounds(ATPA[i]);' then remove the "for J" loop.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  13. #13
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    okay, it worked now but can u explain in examples ( i'm, slow bear with me) by saying what each line is doing and where i went wrong?

  14. #14
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    ok, well we shall simplify it by using an array of Integer's instead of the ATPA and an array of Integer instead of your array of TBox. I would use an array of array of Integer for the ATPA, but GetTPABounds doesn't accept integers.

    SCAR Code:
    var
      i, j: Integer;
      atpa: TIntegerArray;
      TB: TIntegerArray;
    begin
      atpa := [1, 2, 3]; // Set up atpa

      SetLength(TB, Length(atpa)); // Set length to match up with atpa
      for i := 0 to High(atpa) do // loop through atpa
        for j := 0 to High(TB) do // loop through TB
        begin
          TB[j] := atpa[i]; // Assign a value to TB[j], but the key is that i only changes when j has finished looping
          Writeln(IntToStr(i) + ',' + IntToStr(j) + ': ' + IntToStr(TB[j])); // This will show that - j goes 0, 1, 2 then i goes up. As TB[j] will only be given a different value when i changes, it is given the same value until j loops.
        end;
    end.
    Run it and you see that as long as i (left most number) is the same, the value of TB[j] (right most value) is the same even though j (middle number) changes.

    Hopefully this little simplified example will allow you to see where you went wrong before, but if not I'll be more than happy to write down why
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  15. #15
    Join Date
    Aug 2008
    Location
    !!LOL!!
    Posts
    247
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    aah now i understand 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
  •