Log in

View Full Version : out of range



fre
02-14-2012, 07:07 PM
Can someone tell me why this script gives an error out of range?
The error comes at lines with Door[i], if i comment the first line with Door[i] in it it gives an error at the next line with Door[i] in it.

Sometimes the procedure works, sometimes it gives the error.
Spend all day figuerin out why but i can't find it.
i would really appreciate it if someone could help me with this.

Thx

procedure OpenSomeDoors(ReLocate: Boolean);
var
x, y, i, MMDoor: Integer;
DoorColors: TPointArray;
Door: T2DPointArray;
Angle: Extended;
begin
if ReLocate then
begin
MMDoor:= DTMFromString('mWAAAAHicY2FgYFBhY2CwAWInILYF4udAsX tA/AyI3wNxUacew1dmVjj+DxTjR8KMQMyMhEEAABJuCew=');
if FindDTMRotatedAlternating(MMDoor, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/30, Pi/30, Pi/Pi, Angle) then
begin
Mouse(x, y, 1, 1, true);
Flag;
FreeDTM(MMDoor);
wait(1000+random(1000));
end;
end;
if FindColorsSpiralTolerance(MSX2/2, MSY2/2, DoorColors, 3561082, MSX2/2, MSY1, MSX2, MSY2, 25) then
begin
writeln('length = ' + tostr(length(DoorColors)));
Door := SplitTPA(DoorColors, 5);
writeln('length 2 = ' + tostr(length(Door)));
if Length(Door) = 0 then
begin
FindColorsSpiralTolerance(MSX2/2, MSY2/2, DoorColors, 3561082, MSX2/2, MSY1, MSX2, MSY2, 40);
Door := SplitTPA(DoorColors, 5);
end;
for i := 0 to length(Door) do
if (length(Door[i]) > 500) and (length(Door[i]) < 1300) then
begin
Smart_ClearCanvas;
writeln(tostr(length(door[i])));
SMart_drawdots(Door[i]);
wait(500);
MiddleTPAEx(Door[i], x, y);
Mmouse(x, y, 1, 1);
wait(500+random(100));
if IsUpText('lose') then
begin
Writeln('Debuggin purpose');
Exit;
end;
if IsUpText('pen') then
begin
Clickmouse2(True);
writeln('Debugging purpose');
Exit;
end;
writeln('lol');
end;
end;
end;

footballjds
02-14-2012, 07:12 PM
length(Door) should be High(Door)

fre
02-14-2012, 07:13 PM
:o rly?

i was thinking in that diretion and did some rechears.
but i found the both did the same thing except one was faster.
i guess this was wrong.
can u tell me what is the different?

footballjds
02-14-2012, 07:21 PM
:o rly?

i was thinking in that diretion and did some rechears.
but i found the both did the same thing except one was faster.
i guess this was wrong.
can u tell me what is the different?

yes, say we have an array.
Foo[0] := 0;
Foo[1] := 0;
Foo[2] := 0;

the length of the array is 3
the high of the array is 2
So when you use i to length(Foo) you sometimes will ask for Foo[3] which doesn't exist.

You can see exactly what i mean, run the following script:

program new;
var
Foo: TIntegerArray;
i: Integer;

begin

Foo := [1, 2, 3]

for i := 0 to high(Foo) do Writeln(Foo[i]);
for i := 0 to length(Foo) do Writeln(Foo[i]);

end.

fre
02-14-2012, 07:28 PM
Okay i get it.
Thx for the lesson :p

footballjds
02-14-2012, 07:31 PM
Okay i get it.
Thx for the lesson :p

Yup (: anytime dude.
Sorry if I went too far into detail, I just think arrays are very important and understanding them is important (:

masterBB
02-14-2012, 07:44 PM
laptop didn't load complete thread, ignore this ;)