PDA

View Full Version : Help on ATPA clicking



nero_dante
03-11-2015, 05:57 PM
So I have gone through mayors help to try and look for colours create a TPA and then an ATPA but I can't seem to make it run the script keeps coming back as an error. Hopefully someone can help me out :)

program TPAClicking;
{$DEFINE SMART}
{$I SRL-6/SRL.simba}

procedure ClickClimbWall();
var
x, y: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));

if length(TPA) < 1 then
exit;

ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['climb-over'], 500) then
begin
fastClick(MOUSE_LEFT);
break;
end;
end;
end;

begin
smartEnableDrawing := true;
setupSRL();

ClickClimbWall();
end.

Camel
03-11-2015, 06:28 PM
the script keeps coming back as an error


Its because your "i" variable that you use for the for loop is not declared.

So to declare it,

var
x, y, i: integer; // <-- notice the i
TPA: TPointArray;
ATPA: T2DPointArray;

nero_dante
03-11-2015, 07:34 PM
Thanks for the camel, I got it to work... and I tried implementing it into my script, but now I'm getting another error

procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));

if length(TPA) < 1 then
exit;

ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
else begin //getting error here
writeLn('Searching again');
LowWall :=intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
fastClick(MOUSE_LEFT)
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
else begin
writeLn('Could not find');
terminateScript();
end;
end;
end;
end;

This is the error I'm getting
'Error: Found unexpected token "else", expected "End" at line 100
Compiling failed.'

Hoodz
03-11-2015, 07:44 PM
nero_dante;

procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));
if length(TPA) < 1 then
exit;
ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);
for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
begin {added begin here}
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800, 5200));
end {added end here}
else
begin
writeLn('Searching again');
LowWall := intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
begin {added begin here}
fastClick(MOUSE_LEFT) WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800, 5200));
end {added end here}
else
begin
writeLn('Could not find');
terminateScript();
end;
end;
end;
end;

3Garrett3
03-11-2015, 07:47 PM
Thanks for the camel, I got it to work... and I tried implementing it into my script, but now I'm getting another error

procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));

if length(TPA) < 1 then
exit;

ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
else begin //getting error here
writeLn('Searching again');
LowWall :=intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
fastClick(MOUSE_LEFT)
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
else begin
writeLn('Could not find');
terminateScript();
end;
end;
end;
end;

This is the error I'm getting
'Error: Found unexpected token "else", expected "End" at line 100
Compiling failed.'

It's because you're using the if/else statement improperly.

If/then will execute ONLY the line immediately below it if the statement is true. For example:


if True then
writeln('Look it''s true')
else
writeln('Look it''s false');


But what you've got written is


if True then
writeln('It''s true');
clickStuff();
doOtherStuff();
else
writeln('It''s false');


Simba doesn't know why you have an else because there's no if statement above it (that it sees). You also have to note that if you're doing an if/else statement, the line above the else should not have a semicolon. To do what you want, you need to put the code inside a begin/end.

So your script should look like this: (Assuming I guessed where you were trying to go with this)

procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));

if length(TPA) < 1 then
exit;

ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
begin //Add begin here
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
end else //end goes here
begin
writeLn('Searching again');
LowWall :=intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
begin // another begin here
fastClick(MOUSE_LEFT)
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
end else //another end here
begin
writeLn('Could not find');
terminateScript();
end;
end;
end;
end;

Also your standards are a little wonky which makes it harder for folks like me to read your code and notice what went wrong. I fixed them up for you in my code above.

Edit: Damnit hoodz; ninja'd me

nero_dante
03-11-2015, 07:54 PM
Oh thanks a lot @hoodz for what I need to and thanks @3Garrett3 for explaining why :) Also, sory for the messyness of the script. I'll try and keep it cleaner like you have done. :)


Okay so I implemented the correct end else begin, and it runs in the script. But it will do all steps and I only want it to do each step if it fails. I put in what i mean in the code


procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));
if length(TPA) < 1 then
exit;
ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);
for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
begin
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200)); //So It does this, but then it continues to do the next step
end
else
begin
writeLn('Searching again'); //I only want it to do this step If the first step fails.
LowWall :=intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
begin
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
end
else
begin
writeLn('Could not find'); //Same for here, only want it to do this step if it fails the first and then second step
terminateScript();
end;
end;
end;
end;

bonsai
03-11-2015, 09:46 PM
Oh thanks a lot @hoodz for what I need to and thanks @3Garrett3 for explaining why :) Also, sory for the messyness of the script. I'll try and keep it cleaner like you have done. :)


Okay so I implemented the correct end else begin, and it runs in the script. But it will do all steps and I only want it to do each step if it fails. I put in what i mean in the code


procedure ClimbOverLowWall();
var
LowWall: Tbox;
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
findColorsSpiralTolerance(x, y, TPA, 12163981, mainScreen.getBounds(), 6, colorSetting(8, 0.10, 0.86));
if length(TPA) < 1 then
exit;
ATPA := TPA.toATPA(50, 70);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);
for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['limb-over'], 500) then
begin
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200)); //So It does this, but then it continues to do the next step
break; // bonsai - now it will quit the for loop and be done
end
else
begin
writeLn('Searching again'); //I only want it to do this step If the first step fails.
LowWall :=intTobox(245, 238, 257, 276);
mouseBox(LowWall, MOUSE_MOVE);
wait(200);
if isMouseOverText(['limb-over Obstacle']) then
begin
fastClick(MOUSE_LEFT);
WriteLn('Climbing over Low Wall');
wait(gaussRangeInt(4800,5200));
end
else
begin
writeLn('Could not find'); //Same for here, only want it to do this step if it fails the first and then second step
terminateScript();
end;
end;
end;
end;

You have a for loop to run it multiple times against each found spot.

The first time through the loop it's doing the mouse left, the second time it's falling into the else part.

Notice how I added the 'break' in there. That will make it quit the current loop ('for i := ...'). So after it finds and clicks the spot it will stop looping.

nero_dante
03-11-2015, 09:58 PM
You have a for loop to run it multiple times against each found spot.

The first time through the loop it's doing the mouse left, the second time it's falling into the else part.

Notice how I added the 'break' in there. That will make it quit the current loop ('for i := ...'). So after it finds and clicks the spot it will stop looping.

okay cool, does that mean I have to add the break lower down as well, before the bot terminates the script?

3Garrett3
03-11-2015, 10:17 PM
okay cool, does that mean I have to add the break lower down as well, before the bot terminates the script?

You should have a break if the second attempt is successful, in the same way bonsai did for the first attempt.

nero_dante
03-12-2015, 12:05 AM
You should have a break if the second attempt is successful, in the same way bonsai did for the first attempt.

okay cool, thanks :)