SRL Archive - RS3 Help

How to repeat Procedure if something is not found


nero_dante

2015-03-06 06:18:29

Thanks again all for the quik reply and support you guys give and I'm probably going to be bring out quite a few different posts to help me through my beginning scripting days. Hope its okay to all :P

What I'm stuck on n ow, is finding out how to repeat a procedure if it fails. That's the code below. It hovers over the log beam and if it finds the text it clicks, but if it doesn't I want it to repeat the procedure, is there a way of doing that?

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk log bea, log beam') then
fastClick(MOUSE_LEFT)
else begin
writeLn('Can not find Looking again');

WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end;

fastler

2015-03-06 06:51:07

If that were a function that returned true or false depending on it's success, you could then use:
WaitFunc(@functionName, 100, 1000);
It would repeat the function functionName for 1000 ms at an interval of 100 ms or until it returns true.

And by obligation I must mention that using a TBox to locate the log could be better done with the help of color. But I'm sure you'll get to that later on. ;)

cosmasjdz

2015-03-06 06:57:07

From: nero_dante
Thanks again all for the quik reply and support you guys give and I'm probably going to be bring out quite a few different posts to help me through my beginning scripting days. Hope its okay to all :P

What I'm stuck on n ow, is finding out how to repeat a procedure if it fails. That's the code below. It hovers over the log beam and if it finds the text it clicks, but if it doesn't I want it to repeat the procedure, is there a way of doing that?

procedure WalkLogBeam();
var
logBeam: Tbox;
begin
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk log bea, log beam') then
fastClick(MOUSE_LEFT)
else begin
writeLn('Can not find Looking again');

WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end;




program blahaalala;
var t:ttimemarker;

function WalkLogBeam():boolean;// <-function will return if succesfull or not;
var
logBeam: Tbox;
begin
result:=false;//<- declare result as false because you havent clicked it yet;
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk log bea, log beam') then
begin
result:=didclick(true);// <- will give true if mouseclick is red color which means clicked
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end
else writeLn('Can not find'); //<- otherwise if fails result stays at false;
end;
begin

if not walklogbeam() then walklogbeam();// <- will repeat once if didnt clicked on beam
//optional//\

t.start();
repeat
wait(200);
until walklogbeam() or t.gettime()>25000;// <- will repeat untill walks through beam, so need failsafe ttimemarker to stop doing infinity loop after 25 secs for example.

//////////
end;

Edit: by the way started to write it as junior member, now member :) So you should pretty much apreciate it for that amount of time spended ;)

nero_dante

2015-03-06 07:23:58

From: cosmasjdz

program blahaalala;
var t:ttimemarker;

function WalkLogBeam():boolean;// <-function will return if succesfull or not;
var
logBeam: Tbox;
begin
result:=false;//<- declare result as false because you havent clicked it yet;
LogBeam := intTobox(286, 50, 293, 180);
mouseBox(LogBeam, MOUSE_MOVE);
if isMouseOverText('alk log bea, log beam') then
begin
result:=didclick(true);// <- will give true if mouseclick is red color which means clicked
WriteLn('Walking over LogBeam');
wait(gaussRangeInt(5600,5800));
end
else writeLn('Can not find'); //<- otherwise if fails result stays at false;
end;
begin

if not walklogbeam() then walklogbeam();// <- will repeat once if didnt clicked on beam
//optional//\

t.start();
repeat
wait(200);
until walklogbeam() or t.gettime()>25000;// <- will repeat untill walks through beam, so need failsafe ttimemarker to stop doing infinity loop after 25 secs for example.

//////////
end;

Edit: by the way started to write it as junior member, now member :) So you should pretty much apreciate it for that amount of time spended ;)


Oh so making it a function would allow it to work easier than as a procedure. Thanks for that :) … also I didn't understand the last thing you wrote lol xD. However, I did appreciate all help that I get :)

nero_dante

2015-03-06 07:29:46

From: fastler
If that were a function that returned true or false depending on it's success, you could then use:
WaitFunc(@functionName, 100, 1000);
It would repeat the function functionName for 1000 ms at an interval of 100 ms or until it returns true.

And by obligation I must mention that using a TBox to locate the log could be better done with the help of color. But I'm sure you'll get to that later on. ;)


yeah I will be adding the help of colour later on :)