SRL Archive - Help

out of range


fre

2012-02-14 14:07:13

Can someone tell me why this script gives an error out of range?
The error comes at lines with Door, if i comment the first line with Door in it it gives an error at the next line with Door 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('mWAAAAHicY2FgYFBhY2CwAWInILYF4udAsXtA/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

2012-02-14 14:12:10

length(Door) should be High(Door)

fre

2012-02-14 14:13:02

: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

2012-02-14 14:21:35

From: fre
: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

2012-02-14 14:28:38

Okay i get it.
Thx for the lesson :p

footballjds

2012-02-14 14:31:06

From: fre
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

2012-02-14 14:44:01

laptop didn't load complete thread, ignore this ;)