SRL Archive - OSR Help

Out of range error


Kyle

2013-04-07 00:33:29

So, i's still fairly new to ATPA's and I get an out of range error sometimes of this snippet. Anyone have any idea? Please and thanks in advance!
Procedure RedShifter;

var

Shifter1TPA, Shifter2TPA:TPointArray;

ShifterATPA:T2DPointArray;

ShifterBox:TBox;

i:integer;

MSCTP:Tpoint;

begin

MSCTP := Point(MSCX, MSCY);

if findcolorstolerance(Shifter1TPA, 1781205, MSX1, MSY1, MSX2, MSY2, 5) then

begin

ShifterATPA := SplitTPAEx(Shifter1TPA, 30, 30);

SortATPAFrom(ShifterATPA, MSCTP);

for i := 0 to high(ShifterATPA) do

begin

ShifterBox := GetTPABounds(ShifterATPA[i]);

if findcolorstolerance(Shifter2TPA, 4610426, Shifterbox.x1, Shifterbox.Y1, Shifterbox.X2, Shifterbox.Y2, 15) then

begin

mmouse(Shifter2TPA[i].x, Shifter2TPA[i].y,2,2);//OUT OF RANGE ON THIS LINE!

if WaitUpText('ttack', 160) then

begin

clickmouse2(mouse_left);

wait(RandomRange(1500,3900));

end;

end;

end;

end;

end;

Sjoe

2013-04-07 00:52:17

Shifter2TPA[0].x,Shifter2TPA[0].y

Or better yet, put it in another for to do loop like u did for your ATPA


and u should check your TPA/ATPA Lengths after if findcolorstol…..

if Length(A/TPA) < 1 then Exit ; // in case no colors are returned.
This will also prevent out or range errors.


also after :
clickmouse2(mouse_left);
wait(RandomRange(1500,3900));

use Exit; or Break; or it will continue with the loop(unless it's your intention).


EDIT: Try and fix your scripting standards like Le Jingle's style :) It's way easier to read!

Le Jingle

2013-04-07 00:57:20

Sjoekeloe pretty much got it

I'll reiterate what he said, with the addition of it being a code example:
(look for code comments)


procedure RedShifter();
var
i, MidX, MidY: Integer;
Shifter1TPA, Shifter2TPA: TPointArray;
ShifterATPA: T2DPointArray;
ShifterBox: TBox;
begin
FindColorsTolerance(Shifter1TPA, 1781205, MSX1, MSY1, MSX2, MSY2, 5);
if (Length(Shifter1TPA) < 1) then
Exit;

SplitTPAExWrap(Shifter1TPA, 30, 30, ShifterATPA);
SortATPAFrom(ShifterATPA, Point(MSCX, MSCY));

for i := 0 to high(ShifterATPA) do
begin
ShifterBox := GetTPABounds(ShifterATPA[i]);
FindColorsTolerance(Shifter2TPA, 4610426, Shifterbox.x1, Shifterbox.Y1, Shifterbox.X2, Shifterbox.Y2, 15);
if (Length(Shifter2TPA) < 1) then // Make sure we have another TPA to work with, before trying to go out of range ;)
Continue;
MiddleTPAEx(Shifter2TPA, MidX, MidY);
MMouse(MidX, MidY, 2, 2); // Clicks the middle of the TPA, instead of the x1,y1
if WaitUpText('ttack', 160) then
begin
ClickMouse2(Mouse_Left);
Wait(RandomRange(1500, 3900));
Break; // Stop when we've accomplished the goal for the procedure.
end;
end;
end;

Cheers,
Lj

Kyle

2013-04-07 01:05:27

Thanks to both of you so much, I really appreciate it! I'll learn these ATPA's eventually!

Sjoe

2013-04-07 01:15:37

From: elfyyy
Thanks to both of you so much, I really appreciate it! I'll learn these ATPA's eventually!


Seems like you're doing great already though!