SRL Archive - OSR Help

Not digging the double loop... Suggestions?


JTcm

2012-08-25 17:12:14

Pretty much what the title says. Not really happy with this double loop. Any thoughts?


procedure StartBattle();
var
findDTMResultOne, findDTMResultTwo: Boolean;
x1, y1, x2, y2, repeatCounter, failSafe: Integer;
begin
findDTMResultOne := FindDTM(DTMFromString(startButtonDTMString), x1, y1, GSX1, GSY1, GSX2, GSY2);
Mouse(x1, y1, 0, 0, mouse_Left);

// Outer loop with fail safe
failSafe := 0;
repeat
// Inner loop checking if fight has started
repeatCounter := 0;
repeat
Wait(150);
Inc(repeatCounter);
findDTMResultTwo := FindDTM(DTMFromString(fightStartedDTMString), x2, y2, GSX1, GSY1, GSX2, GSY2);
until ((findDTMResultTwo = true) or (repeatCounter > 50));
Inc(failSafe);
until((findDTMResultTwo = true) or (failSafe > 3));

if ((findDTMResultTwo = false) or (failSafe > 3)) then
ThrowErrorAndTerminate('Error starting the fight');
end;

Le Jingle

2012-08-25 17:19:55


procedure StartBattle();
var
x, y, t: integer;
begin
if FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2) then
Mouse(x, y, 0, 0, mouse_Left); {after 1 attempt of trying to find the dtm,
if it's found on the first and only try, it will be left-clicked.}

while (not(FindDTM(DTMFromString(fightStartedDTMString), x, y, GSX1, GSY1, GSX2, GSY2))) do
begin
wait(100);
if (timefrommark(t)>10000) then
exit; {this while .. do loop will repeat waiting 100 ms until 10000 ms,
aka 10 seconds have passed or until the FindDTM is Found to be true. if it
remains unfound for >10000 then it will exit the currecnt procedure.}
end;
end;
Just a thought, don't know exactly what's going on, but perhaps this may help.

JTcm

2012-08-25 18:00:07

Thank you for the suggestion Le Jingle

Here is where I was going and ended up :)


procedure StartBattle();
var
x, y, failSafe: Integer;
loopRuntime: Integer;
begin
[COLOR="RoyalBlue"]// Find and click the start button[/COLOR]
FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2);
Mouse(x, y, 0, 0, mouse_Left);

Wait(1500);
failSafe := 0;
MarkTime(loopRuntime);
while (not(FindDTM(DTMFromString(fightStartedDTMString), x, y, GSX1, GSY1, GSX2, GSY2))) do
begin
[COLOR="RoyalBlue"]// While the fight started DTM is not found wait 150 ms and try again[/COLOR]
Wait(150);

[COLOR="RoyalBlue"]// If we have waited 10 seconds and the fight hasn't started[/COLOR]
if (TimeFromMark(loopRuntime) > 10000) then
begin
[COLOR="RoyalBlue"]// Reset the timer and increment the failSafe counter[/COLOR]
MarkTime(loopRuntime);
Inc(failSafe);

[COLOR="RoyalBlue"]// If we have waited 10 seconds twice then something is wrong[/COLOR]
if (failSafe > 1) then
ThrowErrorAndTerminate('Error Starting Fight');

[COLOR="RoyalBlue"]// If the start button is found click it[/COLOR]
if (FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2)) then
Mouse(x, y, 0, 0, mouse_Left);
end;
end;
end;

mormonman

2012-08-25 18:38:43

You should load your DTMs to a variable so you can free them. That procedure there will hog memory really fast.

JTcm

2012-08-25 23:51:31

From: mormonman
You should load your DTMs to a variable so you can free them. That procedure there will hog memory really fast.


Wow big oversight. Thanks for pointing that out. Fixed now :)