SRL Archive - OSR Help

what to set, to prevent out of range?


Le Jingle

2012-08-14 19:01:03

I can use this function I made, sometimes - once. Then it will highlight or automatically highlight an out of range error, but I can't seem to see the reason/var I need to limit?

The function is suppose to find the given input colors (preferabbly all/all but 1) within a 50x50 ATPA of the TPA(mainscreen). Then that box becomes the result, and we'll click there.

example:

{$include SRL\SRL.simba}

function a_Bank(colors:tintegerarray; tries, tol: integer): boolean;
var
count, lala, i: integer;
bankerTPA: TPointArray;
The_Banker_Box_50_x_50: T2DPointArray;
begin
result := false;
if not loggedin then
exit;
lala := Length(colors);
for count := 1 to high(tries - 1) do
begin
for i := 0 to high(lala) do
if findcolorstolerance(bankerTPA, colors[i], msx1, msy1, msx2, msy2, tol) then
// Out of Range @ this line above ^^^
begin
SortATPAFrom(The_Banker_Box_50_x_50, Point(MSCX, MSCY));
SplitTPAWrap(bankerTPA, 50, The_Banker_Box_50_x_50);
if TPAInATPA(bankerTPA, The_Banker_Box_50_x_50, i) then
begin
mouse(The_Banker_Box_50_x_50[i][i].x, The_Banker_Box_50_x_50[i][i].y, 5, 5, mouse_right);
result := waitoption('nk Ba', 1000);
exit;
end;
end;
if count >= tries then
exit;
end;
end;

begin
SetupSRL;
a_Bank([14474983, 7576783, 5059387, 6505035, 3230297], 5, 5);
end.

Any help on this would be much appreciated!

fre

2012-08-14 19:04:18

if findcolorstolerance(bankerTPA, colors, msx1, msy1, msx2, msy2, tol) then

That is the reason of the error.
To solve it u must do this

lala := Length(colors);
->
lala := High(colors);

let me know how it goes

eska

2012-08-14 19:04:26

Obviously it's the variable Colors that is causing the out of range.

You are also doing some wierd stuff with 'lala'. Not a great name for a variable either.

{$include SRL\SRL.simba}

function a_Bank(colors:tintegerarray; tries, tol: integer): boolean;
var
count, lala, i: integer;
bankerTPA: TPointArray;
The_Banker_Box_50_x_50: T2DPointArray;
begin
result := false;
if not loggedin then
exit;
lala :=high(colors);
for count := 1 to high(tries - 1) do
begin
for i := 0 to lala do
if findcolorstolerance(bankerTPA, colors[i], msx1, msy1, msx2, msy2, tol) then
begin
SortATPAFrom(The_Banker_Box_50_x_50, Point(MSCX, MSCY));
SplitTPAWrap(bankerTPA, 50, The_Banker_Box_50_x_50);
if TPAInATPA(bankerTPA, The_Banker_Box_50_x_50, i) then
begin
mouse(The_Banker_Box_50_x_50[i][i].x, The_Banker_Box_50_x_50[i][i].y, 5, 5, mouse_right);
result := waitoption('nk Ba', 1000);
exit;
end;
end;
if count >= tries then
exit;
end;
end;

begin
SetupSRL;

fre

2012-08-14 19:09:36

Do you know the difference between Lenght and High?
It is an important difference, lookup a small tut about it.
Espacially for loops you must know the difference.

If you can't find any tut about it, let me know here and i ll explain.

Le Jingle

2012-08-14 19:32:21

Oh thanks! Works like a charm now >.< I don't/didn't know the difference, really at all, before this. I used Google and got some cool information, more than I was expecting. For example, the difference between categorical, ordinance, and interval variables (here). I also found a tutorial relative to distinguishing the differences from length (here) to high.

So from what I understand, Length() would return how many variables are being measured, and high() would return the largest/highest variables being measured? I suppose this is why my code messed up, as I looked up until the length of 'lala' instead the highest count of 'lala'?
So…

var
arr: TIntegerArray;
begin
x := [5, 6, 7, 2, 7, 9];
Length(arr); //6. B/c there are 6 integers within the array, right?
High(arr); //9. B/c we're grabbing the highest possible integer within arr?
end.
Thanks all for the feedback, helped me a lot!

Runaway

2012-08-14 19:47:11

From: Le Jingle
So from what I understand, Length() would return how many variables are being measured, and high() would return the largest/highest variables being measured? I suppose this is why my code messed up, as I looked up until the length of 'lala' instead the highest count of 'lala'?
So…

var
arr: TIntegerArray;
begin
x := [5, 6, 7, 2, 7, 9];
Length(arr); //6. B/c there are 6 integers within the array, right?
High(arr); //9. B/c we're grabbing the highest possible integer within arr?
end.
Thanks all for the feedback, helped me a lot!


Close, but not quite :p

High() returns the location of the last stored value, and Length() returns the number of stored values. Since arrays start at 0, the length is always (I think?!..?) 1 greater than the high of an array.

For example:


var
Arr: TIntegerArray;

Arr := [1, 5, 3, 2];

High(Arr) would be 3 since Arr[3] is the location of the last stored integer.
Length(Arr) would be 4 since the array has 4 values.

So they are pretty much interchangeable since:


High(Arr) = Length(Arr) - 1
Length(Arr) = High(Arr) + 1

Hope that clears things up :)

Le Jingle

2012-08-14 19:54:53

How come the last stored integer isn't 2?
Is it the second to last integer in the array or is there something I'm missing blindly?
Or is it that the last stored integer is technically 3, not 2?

Kasi

2012-08-14 20:06:40

High returns then Length of the array - 1, and length returns the length of the array.
so if a array had 11 elements then length would return 11, and high would return 10 :P
Edit: basically what runaway said in simpler terms i guess?

Runaway

2012-08-14 20:08:25

From: Runaway
location of the last stored integer


The keyword is location. High() returns the location, relative to the array, of the last stored value. So if you do:


Arr := [1, 2, 3];
// or
Arr := [0, 1, 2, 3];
// or
Arr := [-1, 0, 1, 2, 3];

Writeln(Arr[High(Arr)]);

It will debug 3 every time since High(Arr) returns 2, 3 and 4 respectively. Here's a little table to simplify things:


Array: [1, 2, 3]
High(Array): 2
Array[High(Array)]: 3

Array: [5, 14, 2, 8]
High(Array): 3
Array[High(Array)]: 8

Array: [0, 1, 11, 3, 6]
High(Array): 4
Array[High(Array)]: 6

Just compare the relationship between those 3 example arrays and I think you'll understand as fully as possible :p

Le Jingle

2012-08-14 20:35:56

Oh that makes a lot more sense now. I thought at first, that the indexed number in the array was the second to last / the result of High(); So I now know that High(); takes the count of the array - 1. Then length does simply the entire count of the array, right?

Runaway

2012-08-14 20:40:45

From: Le Jingle
Oh that makes a lot more sense now. I thought at first, that the indexed number in the array was the second to last / the result of High(); So I now know that High(); takes the count of the array - 1. Then length does simply the entire count of the array, right?


Exactly. If arrays started at 1 instead of 0, then High() and Length() would always be the same.