SRL Archive - Help and Support

Runtime Error Help:


Daniel

2008-03-13 05:28:16

Here is the line which my error appears on:

function FindColorsMulti(Colors: TIntegerArray; x, y, xs, ys, xe, ye, ToleranceLevel: Integer): Boolean;
var i: Integer;
begin
for i:=0 to Length(Colors) do
begin
Result:=FindColorTolerance(x,y,Colors[i],xs,ys,xs,ye,ToleranceLevel);
if(Result) then i:=Length(Colors);
end;
end;

Here is my error:
[Runtime Error] : Out Of Range in line 662 in script C:\Program Files\SCAR 3.14\Scripts\ipowerminer.scar

Please help as i really want to finally release this power-miner to the public.

Thanks,
IP-Drowner!

Santa_Clause

2008-03-13 06:32:44

for i:=0 to Length(Colors) do

Since the array index starts from 0, it ends at Length(Array) - 1.

It should be:

for i:=0 to Length(Colors) - 1 do

Better yet :

for i:=0 to High(Colors) do

High is an in-built SCAR function which returns the the length of the array minus one.

ZephyrsFury

2008-03-13 06:36:59

And I think you want to put in a 'Break' if it finds the colour so it exits the loop if a colour is found.

n3ss3s

2008-03-13 14:31:05

High is an in-built SCAR function which returns the the length of the array minus one.


Length = High - Low + 1.

Sir R. M8gic1an

2008-03-13 16:45:32

High will return the last index of the array. which in this case is the same as length - 1 cus the array is dynamic and starts at zero.

Arr: array[15..38] of integer;

High(Arr) = 38
GetLength(arr) = 24;

and like zephyr said
if(Result) then break;

~RM

Daniel

2008-03-14 01:30:16

So that's what High means. I saw it in one of Pyros script and i have been wondering ever since (Because i tested it with the numeral 1 inside the rbackets and it returned a number greater than 10000) and i thought i might leave it alone because i never understood it correctly.

Thanks for your help guys :)

Also Zeph, i might just do that ;)