SRL Archive - RS3 Help

Help with simple question?


aHoodMan

2015-06-07 23:22:26

I'm new to scripting and I have a basic question. In my script I have a procedure which searches for an object which is the following:



procedure findObject

var
x, y, i: integer;

begin
mainscreen.findObject(x, y, 5000798, 3, colorSetting(2, 6.02, 6.19), mainscreen.playerPoint, 15, 6, 3, ['ntrance'], MOUSE_LEFT);
wait(7000);

end;



My question is how can I make it so if it doesn't find that object say in 5 seconds, it just stops looking for that object and continues on with the script?

fady

2015-06-07 23:25:30

procedure findObject();

var
x, y, i: integer;
failTimer:TTimeMarker;

begin
failTimer.start;
repeat
if mainscreen.findObject(x, y, 5000798, 3, colorSetting(2, 6.02, 6.19), mainscreen.playerPoint, 15, 6, 3, ['ntrance'], MOUSE_LEFT) then
break;
until (failTimer.getTime > 5000);
if failTimer.getTime > 5000 then
exit;
end;

Try that. I'm assuming by continue with the script, that skips the rest of the procedure where it finds the object and moves to the next procedure, and if it finds the object it will follow through with the rest of the current procedure.

aHoodMan

2015-06-07 23:43:14

I put in your code and it just kept searching for the object. For some reason it ignored the 5 seconds and just kept looking for the object for like 30 seconds.

fady

2015-06-08 00:03:38

From: aHoodMan
I put in your code and it just kept searching for the object. For some reason it ignored the 5 seconds and just kept looking for the object for like 30 seconds.


Well mainScreen.findObject will attempt to do the mouse action at every matching color detected, so if the color of what you are looking for is everywhere, it is going to loop through all of them trying to find the mouseOverText. I suggest using findColorsSpiralTolerance and then limiting by size to try and maybe eliminate some of the extra ones

something like this


procedure findStuff();
var
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;

begin
findColorsSpiralTolerance(x, y, TPA, 5000798, mainscreen.getBounds(), 3, colorSetting(2, 6.02, 6.19));

if (Length(TPA) < 1) then
exit;

ATPA := TPA.toATPA(20, 20); //play around with this (these numbers are the dimensions of the ATPAs)
ATPA.sortFromMidPoint(mainscreen.playerPoint);
FilterTPAsBetween(ATPA,1,110); //and this (will ignore the TPAs that have a size between the specified numbers)

smartImage.debugATPA(ATPA);

end;

untill the debug shows you something that isn't too insane. Once you settle on a setting that works. Add this

for i := 0 to high(ATPA) do
begin
mouse(ATPA[i].getBounds().getRandomPoint());
if isMouseOverText(['ntrance']) then
begin
fastClick(MOUSE_LEFT);
break;
end;
end;


instead of the smartimage.debugATPA line, and that should make it work a little better.