SRL Archive - Jr. Member General Help and Discussion

Function not exiting True


RlagkRud

2014-07-18 13:00:24

Hey guys this is an excerpt from my SawMill script.
Sometimes, the script clicks on the sawmill but exits false. I have no idea why.
Here's the cod:
Function FindSawMill: boolean;
var
x, y, i : integer;
ZeroCoor : TPoint;
TPA : TPointArray;
ATPA: T2DPointArray;
T : TTimeMarker;
begin

If Not IsLoggedIn Then
Exit;

smartimage.clear;

T.reset;
T.start;


Repeat
wait(randomrange(250,500));
if findColorsSpiralTolerance(x, y, TPA, 3173016, mainscreen.getbounds, 6, colorSetting(2, 0.30, 0.11)) then
break;
If (Not IsLoggedIn) Then
Exit;

if SawmillTime.GetTime > 5 * 60 * 1000 then
begin
Writeln('Couldnt find a mill for 5 minutes! Terminating!');
TerminateScript;
end;

Until (False);

ATPA := TPA.toATPA(50,30);
ATPA.filterBetween(0, 300);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

if length(ATPA) = 0 then
FindSawMill;

for i := 0 to high(ATPA) do
begin
writeln(length(ATPA[i]));
Obx := middleTPA(ATPA[i]).x ;
Oby := middleTPA(ATPA[i]).y ;
mouse(Obx-7, Oby-7, 14, 14, mouse_move);

If (IsMouseOverText(['Make p','planks'])) Then
Begin

fastclick(mouse_left);
Timeout.reset;
Timeout.start;
Result := True;
Exit;

end else
begin

FindSawMill;

end;
end;


end;

Any help would be great! Thanks!
Thinking of releasing this as soon as this and some other bugs get fixed.

Turpinator

2014-07-18 13:17:58

its because you call it recursively. the first time through, it might not find the sawmill, so it enters the function again and that second (or third, or fourth, or…) is the one thats clicking and returning true.

so to rectify this, turn FindSawMill; (towards the end) to result := FindSawMill;

or dont call it recursively.

RlagkRud

2014-07-18 13:45:50

From: Turpinator
its because you call it recursively. the first time through, it might not find the sawmill, so it enters the function again and that second (or third, or fourth, or…) is the one thats clicking and returning true.

so to rectify this, turn FindSawMill; (towards the end) to result := FindSawMill;

or dont call it recursively.


Figures the problem was recursion.
This seems to have fixed it. Thanks!