SRL Archive - Help and Support

Function help


Le Jingle

2012-11-12 15:47:10

Hi, I'm trying to iron out some bugs in a script I'm working on, and one of the bugs is an out of range error when it comes to clicking..

Here's the original code:

function MS_Find(colors: TIntegerArray; SortFromX, SortFromY,
SplitW, SplitH: integer; upText:string): boolean;
var x: integer;
var y: integer;
var i: integer;
var ii: integer;
var t: integer;
var hCols: integer;
var hATPA: integer;
var temp: TPointArray;
var ClearPoints: TPointArray;
var ClearPlayer: TPointArray;
var ATPA: T2DPointArray;
begin
result := false;
if not loggedin then
exit;
hCols := High(colors);
ClearPlayer := TPAFromBox(IntToBox(240, 130, 275, 185));
marktime(t);

if findcolorsspiraltolerance(MSCX, MSCY, temp, colors[i], MSX1, MSY1, MSX2, MSY2, 15) then
begin
ClearTPAFromTPAWrap(temp, ClearPlayer, temp);
Dbg('Cleared Player TPA, Length is now = '+ToStr(length(temp))+'.');

for i := 0 to hCols do
begin
{$IFDEF SMART}
if (Players[0].Booleans[2]) then
SMART_DebugTPA(true, temp);
{$ENDIF}

Dbg('Loop 1, Index '+ToStr(i)+' : Possible # of TPA Points = '+ToStr(length(temp))+'.');

SortTPAFrom(temp, Point(SortFromX, SortFromY));

SplitTPAExWrap(temp, SplitW, SplitH, ATPA);

if (length(ATPA) < 1) then
begin
Dbg('No points to work with, breaking');
break;
end;

hATPA := high(ATPA);

{$IFDEF SMART}
if (Players[0].Booleans[2]) then
SMART_DebugATPA(true, ATPA);
{$ENDIF}

for ii := 0 to hATPA do
begin
if (TimeFromMark(t)>=25000) then
break;

Dbg('Entered 2nd loop, ATPA. ATPA Length = ' + ToStr(Length(ATPA)) + '.');

if (Length(ATPA)>1) then
SortATPASize(ATPA, true);

writeln(i);
writeln(ii);

Mouse(ATPA[i][ii].x, ATPA[i][ii].y, 0, 0, mouse_right);

if WaitOptionFuzzy(upText, MATCH_GOOD, 2500) then // Zmons' genius
begin
Dbg('Result = FOUND!');
result := true;
exit;
end else
begin

case random(4) of
0..1: MMouse(x+random(40), y+random(50), 5+random(25), 5+random(25));
2: MMouse(x-random(40), y-random(50), 5+random(25), 5+random(25));
3: MMouse(x+random(40), y-random(50), 5+random(25), 5+random(25));
4: MMouse(x-random(40), y+random(50), 5+random(25), 5+random(25));
end;

DeleteValueInATPA(ATPA, ii);

hATPA := hATPA - 1;

Dbg('Removed index ['+ToStr(ii)+'] from ATPA.');
end;
end;
end;
end;
end;

Here's a compile-able version:

Program Test;
{$i srl/srl.simba}

function MS_Find(colors: TIntegerArray; SortFromX, SortFromY,
SplitW, SplitH: integer; upText:string): boolean;
var
x,y,i,ii,t,hCols,hATPA: integer;
TPA, ClearPoints, ClearPlayer: TPointArray;
ATPA: T2DPointArray;
begin
result := false;
if not loggedin then
exit;
hCols := High(colors);
ClearPlayer := TPAFromBox(IntToBox(240, 130, 275, 185));
marktime(t);

if FindColorsSpiralTolerance(MSCX, MSCY, TPA, colors[i], MSX1, MSY1, MSX2, MSY2, 15) then
begin
ClearTPAFromTPAWrap(TPA, ClearPlayer, TPA);
writeln('Cleared Player TPA, Length is now = '+ToStr(length(TPA))+'.');

for i := 0 to hCols do
begin
writeln('Loop 1, Index '+ToStr(i)+' : Possible # of TPA Points = '+ToStr(length(TPA))+'.');

SortTPAFrom(TPA, Point(SortFromX, SortFromY));

SplitTPAExWrap(TPA, SplitW, SplitH, ATPA);

if (length(ATPA) < 1) then
begin
writeln('No points to work with, breaking');
break;
end;

hATPA := high(ATPA);

for ii := 0 to hATPA do
begin
if (TimeFromMark(t)>=25000) then
break;

writeln('Entered 2nd loop, ATPA. ATPA Length = ' + ToStr(Length(ATPA)) + '.');

if (Length(ATPA)>1) then
SortATPASize(ATPA, true);

writeln(i);
writeln(ii);

Mouse(ATPA[i][ii].x, ATPA[i][ii].y, 0, 0, mouse_right);

if WaitOption(upText, 2500) then
begin
writeln('Result = FOUND!');
result := true;
exit;
end else
begin

case random(4) of
0..1: MMouse(x+random(40), y+random(50), 5+random(25), 5+random(25));
2: MMouse(x-random(40), y-random(50), 5+random(25), 5+random(25));
3: MMouse(x+random(40), y-random(50), 5+random(25), 5+random(25));
4: MMouse(x-random(40), y+random(50), 5+random(25), 5+random(25));
end;

DeleteValueInATPA(ATPA, ii);

hATPA := hATPA - 1;

writeln('Removed index ['+ToStr(ii)+'] from ATPA.');
end;
end;
end;
end;
end;

begin
SetupSRL;

end.

The debug usually tells me I have a Length of 1 in my ATPA…
Goes out of range at the Mouse() line.

Any help or advice would be nice.

Cheers,
Lj!

Runaway

2012-11-12 16:03:24

Hey LJ,

It looks like the issue is with the integer i. It reflects the color currently being searched for, but you've used it calling your ATPA:


Mouse(ATPA[i][ii].x, ATPA[i][ii].y, 0, 0, mouse_right);

Since the ATPA can have more than one grouping for each color, it looks like you'll need to go by something different.

Le Jingle

2012-11-12 16:07:59

So if I created an int like j in the first loop, could I use that (after I've assigned i to j) instead in the mouse call?

Thanks for the quick reply! :)

Runaway

2012-11-12 16:22:34

From: Le Jingle
So if I created an int like j in the first loop, could I use that (after I've assigned i to j) instead in the mouse call?

Thanks for the quick reply! :)


Well what you want to be using in the mouse call is ii (since it's the length of the ATPA) and j as the length of each TPA within the ATPA.

Now that I look at it again, you need to be using the ii as the primary index for the ATPA:


//...

if (length(ATPA) < 1) then
begin
writeln('No points to work with, breaking');
break;
end;

if (Length(ATPA)>1) then
SortATPASize(ATPA, true);

hATPA := high(ATPA);

for ii := 0 to hATPA do
begin
if (TimeFromMark(t)>=25000) then
break;

writeln('Entered 2nd loop, ATPA. ATPA Length = ' + ToStr(Length(ATPA)) + '.');

//if (Length(ATPA)>1) then
// SortATPASize(ATPA, true);

writeln(i);
writeln(ii);

//Mouse(ATPA[i][ii].x, ATPA[i][ii].y, 0, 0, mouse_right);
Mouse(MiddleTPA(ATPA[ii]).x, MiddleTPA(ATPA[ii]).y, 0, 0, mouse_right);

//...

I think the out of range was since you had the ii selecting the wrong index. If you want to use j you would have to put it inside the ii loop if you're pickin' up what I'm throwing down. And no problemo :) It's been a long time since I've coded so it's quite refreshing to delve into it a bit!

Le Jingle

2012-11-12 17:38:05

From: Runaway
Well what you want to be using in the mouse call is ii (since it's the length of the ATPA) and j as the length of each TPA within the ATPA.

Now that I look at it again, you need to be using the ii as the primary index for the ATPA:


//...

if (length(ATPA) < 1) then
begin
writeln('No points to work with, breaking');
break;
end;

if (Length(ATPA)>1) then
SortATPASize(ATPA, true);

hATPA := high(ATPA);

for ii := 0 to hATPA do
begin
if (TimeFromMark(t)>=25000) then
break;

writeln('Entered 2nd loop, ATPA. ATPA Length = ' + ToStr(Length(ATPA)) + '.');

//if (Length(ATPA)>1) then
// SortATPASize(ATPA, true);

writeln(i);
writeln(ii);

//Mouse(ATPA[i][ii].x, ATPA[i][ii].y, 0, 0, mouse_right);
Mouse(MiddleTPA(ATPA[ii]).x, MiddleTPA(ATPA[ii]).y, 0, 0, mouse_right);

//...

I think the out of range was since you had the ii selecting the wrong index. If you want to use j you would have to put it inside the ii loop if you're pickin' up what I'm throwing down. And no problemo :) It's been a long time since I've coded so it's quite refreshing to delve into it a bit!


Ah I see what you mean! You've taught me much about this in the past too, and I understand what you mean :) I thought it was somewhat awkward using the Mouse call with those parameters; needless to say you've explained it and I totally forgot about Middle TPA.

Good to see you still around helpin' out!

Cheers,
Lj!