SRL Archive - OSR Help

Loop executes just once?


m34tcode

2012-03-29 23:36:47

This function, it works for normal banks. for bankchests it seems not to. Why, I have no idea, as its the same function in both scenarios…

This loop only executes once on bank chests…


DebugStr(3,'Waiting for bank and pin screens...');
MarkTime(T);
while (not BankScreen) and (not PinScreen) and (TimeFromMark(T) < RandomRange(5000,10000)) do
begin
writeln('bscreen: ' + booltostr(BankScreen));
writeln('pscreen: ' + booltostr(PinScreen));
writeln(TimeFromMark(T));
wait(100+random(50));
end;

The open bank chest function , and the one containing that loop, is here:

function PinAndBankTest:Boolean;
var
T : LongInt;
begin
if not LoggedIn then
Exit;

Result := false;

DebugStr(3,'Waiting for bank and pin screens...');
MarkTime(T);
while (not BankScreen) and (not PinScreen) and (TimeFromMark(T) < RandomRange(5000,10000)) do
begin
writeln('bscreen: ' + booltostr(BankScreen));
writeln('pscreen: ' + booltostr(PinScreen));
writeln(TimeFromMark(T));
wait(100+random(50));
end;

if PinScreen then
begin
DebugStr(2,'Entering pin...');
if Length(Players[CurrentPlayer].Pin) = 0 then
begin
DebugStr(2,'You did not set a pin, but we are in the pin screen... ' +
'Next player...');

Logout;
NextPlayer(False);

Exit;
end;
inpin(Players[CurrentPlayer].Pin);
end;


DebugStr(3,'Waiting for bank screen...');
MarkTime(T);
while not BankScreen and (TimeFromMark(T) < 5000) do
wait(50+random(50));

Result := BankScreen;
if Result then
begin
DebugStr(2,'Bank opened succesfully');
FixBank;
end else
DebugStr(2,'Did not find Bank Screen');
end;

function Open_BankChest : Boolean;
var
OpenSuccess : Boolean;
a,b,I : Integer;
TP : TPoint;
ChestTPA : TPointArray;
ChestATPA : T2DPointArray;
begin
Result := False;

//first try the recorded bank spot
MakeCompass('e');
SetAngle(SRL_ANGLE_HIGH);

MMouse(ChestBankPoint.x,ChestBankPoint.y,6,6);
DebugStr(3,'Testing for BankChest');
if TestRightClickMenu(['Bank'],ChestBankPoint,4,4,1,true) then
begin
DebugStr(3,'Remembered Bank Chest position, opening bank...');
ChooseOption('Bank');
end else
DebugStr(3,'Did not remember bank chest position, searching now...');

SetColorToleranceSpeed(2)
SetColorspeed2Modifiers(0.110,0.49);

FindColorsSpiralTolerance(a,b,ChestTPA,11974595,MSX1,MSY1,MSX2,MSY2,14);

ChestATPA := TPAtoATPA(ChestTPA,40);

DebugStr(5,'Looping ' +inttostr(Length(ChestATPA)-1) + ' times in search of bank chest');
for I := 0 to Length(ChestATPA)-1 do
begin
TP := MiddleTPA(ChestATPA[I]);

if TestRightClickMenu(['Bank'],TP,3,3,1,false) then
begin

OpenSuccess := ChooseOption('Bank');
DebugStr(3,'Found Bank Chest; Banking success: '+BoolToStr(OpenSuccess));

if OpenSuccess then
begin
ChestBankPoint := TP;
break;
end;
end;
end;

if OpenSuccess then
Result := PinAndBankTest;
end;

Anyone see anything I'm missing?

BobboHobbo

2012-03-30 18:25:14

I dont quite understand, what you mean?

m34tcode

2012-03-30 18:26:50

When I execute that loop, it immediately breaks and continues with script. It doesn't loop until bank or pin screen is found. I tried print the values, but they both are false when it breaks

Abu

2012-03-30 18:27:07

To loop a function you use repeat..until - I haven't seen you use that anywhere :confused:

m34tcode

2012-03-30 18:56:00

I used a while do loop

It is one of the loop structures, along with for..to..do and repeat..until

=]

Nexz

2012-03-30 19:33:04

Tried what happens when you use if..then and repeat..untill instead of while..do?

Caotom

2012-03-30 19:39:21

Is it possibly because one of your failsafe conditions can rr down to around 5 seconds?
I really cannot see anything wrong with that, have you tried replacing the while with a repeat and until(-conditions-) and checked if that works?

~Caotom

BobboHobbo

2012-03-30 20:12:16

  
MarkTime(c);
repeat
Wait(100);
until (BankScreen) or (PinScreen) or (TimeFromMark(c) > 5000);
If ((TimeFromMark(c) > 5000)) Then
Result := False;
Result := (BankScreen) or (PinScreen);
If not Result then Writeln('Problem with banking');

From what Im trying to understand from that fuction, your basically trying to do that ?

m34tcode

2012-03-30 20:56:28

That is essentially the same as a while loo, excluding the fact that it will always execute once. right?

I would test but im capping at cit >.>

Nexz

2012-03-31 17:29:50

From: m34tcode
That is essentially the same as a while loo, excluding the fact that it will always execute once. right?

I would test but im capping at cit >.>

That's correct but trail-and-error still oftenly solves it ;P