SRL Archive - Help and Support

Out of Range Error


Dynamite

2011-12-23 11:35:31

Why does the line specified result in an Out of Range Error?

Function MineOre(which: TOre; Var X, Y : Integer; X1, Y1, X2, Y2 : Integer): Boolean;
Var
TPA : TPointArray;
ATPA : T2DPointArray;
T: TPoint;
K, G, Z: Extended;
Colors: array [0..1] of tIntegerArray;
I, J, xX, yY, Blah: Integer;
DoubleTPA: array [0..1] of TPointArray;
wat: array [0..1] of Integer;
begin
if not LoggedIn then Exit;
ColorToleranceSpeed(2);
for I := 0 to 1 do
begin
SetColorSpeed2Modifiers(which.RockTPA[I][Hue], which.RockTPA[I][Sat]);
FindColorsTolerance(DoubleTPA[I], which.RockTPA[I][Colour], MSx1, MSy1, MSx2, MSy2, which.RockTPA[I][Tol]);
Debug('Length of TPA = '+IntToStr(Length(DoubleTPA[I])));
if Length(DoubleTPA[I]) = 0 then
Exit;
Colors[I] := GetColors(DoubleTPA[I]);
Debug('Length of Colors = '+IntToStr(Length(Colors[I])));
for J := 0 to high(Colors[I]) do
begin
ColorToXYZ(Colors[I][J], K, G, Z);
if InRange(Round(K), 35, 49) then
if InRange(Round(G), 36, 50) then
if InRange(Round(Z), 38, 54) then
begin
wat[I] := J;
Debug('Which['+IntToStr(I)+'] = '+IntToStr(J));
Break;
end;
end;
end;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.20, 0.20);

Repeat
SetArrayLength(TPA, 0);
FindColorsTolerance(TPA, Colors[J][wat[J]], MSX1, MSY1, MSX2, MSY2, 3); // THIS LINE
if Length(TPA) <= 0 then
Exit;
ATPA := TPAToATPAEx(TPA, 25, 25);
SortATPASize(ATPA, true);
for I := 0 to high(ATPA) do
begin
if I = 3 then
Break;
T := MiddleTPA(ATPA[I]);
MMouse(T.x, T.y, 5, 5);
Wait(400 + Random(200));
if WaitUpTextMulti(which.Uptext, 350) then
begin
getMousePos(xX, yY);
Blah := RandomRange(0, DependClick);
if Blah = 0 then begin
Mouse(xX, yY, 0, 0, False);
WaitOption('ine', 500)
end else Mouse(xX, yY, 0, 0, True);
Result := True;
Blah := 0;
Exit;
end;
Inc(J);
end;
until J > 1;
Debug('Found the rock!');
End;

-Boom

Kyle Undefined

2011-12-23 11:47:59

Add this to your script, it may not compile.


SetArrayLength(TPA, 0);
WriteLn('J = ' + IntToStr(J));
WriteLn('Colors.Length = ' + IntToStr(Length(Colors)));
WriteLn('Colors.wat.Length = ' + IntToStr(Length(Colors[J][wat])));
FindColorsTolerance(TPA, Colors[J][wat[J]], MSX1, MSY1, MSX2, MSY2, 3); // THIS LINE

Dynamite

2011-12-23 11:56:27

It doesn't compile?? :s

-Boom

Kyle Undefined

2011-12-23 12:42:39

What's the error?

Dynamite

2011-12-23 12:49:39

Type mismatch at line 267

WriteLn('Colors.wat.Length = ' + IntToStr(Length(Colors[J][wat])));

-Boom

Kyle Undefined

2011-12-23 12:53:14

Ohh I'm so dumb…Your Colors var is only filled in with one dimension. So "Colors[J][wat[J]]" doesn't exist.

Shuttleu

2011-12-23 13:00:16

try this and let me know what it outputs
    WriteLn('J = ' + IntToStr(J));
WriteLn('wat[j] = ' + IntToStr(Length(wat[j])));
FindColorsTolerance(TPA, Colors[J][wat[J]], MSX1, MSY1, MSX2, MSY2, 3); // THIS LINE

~shut

Dynamite

2011-12-23 13:42:51

J = 20
Error: Out Of Range at line 266

line 266:

WriteLn('wat[j] = ' + IntToStr(Length(wat[j])));

-Boom

Kyle Undefined

2011-12-23 13:43:57

Do "Length(wat)"

Shuttleu

2011-12-23 13:45:05

the reason for the error is that j = 20 but wat is only 2 long

so wat[20] is out of range

try this
j:= 0;
WriteLn('J = ' + IntToStr(J));
WriteLn('wat[j] = ' + IntToStr(Length(wat[j])));
FindColorsTolerance(TPA, Colors[J][wat[J]], MSX1, MSY1, MSX2, MSY2, 3); // THIS LINE

~shut

Dynamite

2011-12-23 13:51:17

From: Kyle Undefined
Do "Length(wat)"


WriteLn('wat = ' + IntToStr(Length(wat)));

wat = 2

Shuttleu

2011-12-23 13:52:39

just as i said a couple of posts up

~shut

Dynamite

2011-12-23 13:56:10

From: Shuttleu
just as i said a couple of posts up

~shut


yep and:

Length of TPA = 52
Length of Colors = 52
Length of TPA = 18
Length of Colors = 18
J = 0
Error: Type Mismatch at line 267

Shuttleu

2011-12-23 13:59:59

do you mind if i see the whole script?

~shut

Dynamite

2011-12-23 14:01:25

Sure I will PM you link :)

-Boom

Shuttleu

2011-12-23 14:02:27

wait, i think i noticed
j:= 0;
WriteLn('J = ' + IntToStr(J));
WriteLn('wat[j] = ' + IntToStr(Length(wat)));
FindColorsTolerance(TPA, Colors[J][wat[J]], MSX1, MSY1, MSX2, MSY2, 3); // THIS LINE

~shut