Log in

View Full Version : A little tiny problem



Archaic
02-26-2012, 01:39 AM
I've been recently been using a couple of TPA's to find obstacles in the wilderness agility course. After a lot of trial and error, I've got these functions working fine, I'm just having troubles understanding how to either 1. create a procedure with them or 2. put them in the main loop.

These is a sample of a couple of my TPA's:

program new;
{$DEFINE SRL5}
{$i SRL/srl.simba}

Var

X, Y: integer;

function FindObstaclePipe(Var X, Y : Integer): Boolean;
var
TPA : TPointArray;
ATPA : T2DPointArray;
I, H : Integer;
Begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 0, MSX1, MSY1, MSX2, MSY2, 15);
ATPA := TPAtoATPA(TPA, 25);
If Length(ATPA) = 0 Then
Exit;
H := High(ATPA);
For I := 0 To H Do
Begin

MiddleTPAEx(ATPA[I], X, Y);
MMouse(X, Y, 3, 3);
Wait(50 + Random(50));
If IsUpText('queeze') Then
Begin
Writeln('Found Obstacle Pipe!');
GetMousePos(X, Y);
MMouse(x, y, 3, 3);
Mouse(x, y, 0, 0, 1);
Result := True;
Wait(5000+random(2000));
Exit; //<------Problem
End;

end;
End;

function FindRopeSwing(Var X, Y : Integer): Boolean;
var
TPA1 : TPointArray;
ATPA1 : T2DPointArray;
SwingColor, I, H : Integer;
Begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA1, SwingColor, 290, 8, 296, 55, 2);
ATPA1 := TPAtoATPA(TPA1, 10);
If Length(ATPA1) = 0 Then
Exit;
H := High(ATPA1);
For I := 0 To H Do
Begin
MiddleTPAEx(ATPA1[I], X, Y);
MMouse(X, Y, 2, 2);
Wait(50 + Random(50));
If WaitUpText('wing-on', random(500)) Then
Begin
Writeln('Found Rope Swing!');
GetMousePos(X, Y);
MMouse(X, Y, 1, 2);
Mouse(X, Y, 0, 0, 1);
Result := True;
Exit;
End;
End;
End;


begin
SetUpSRL;
FindObstaclePipe(X, Y);
FindRopeSwing(X, Y);
end.

My problem arises from looping. I'm sure it's probably something simple that I'm overlooking but every time I run this simple main loop it either:

1. If Exit is included in first function, then it completes the FindObstaclePipe function then completely ends the script, without even attempting the second function, FindRopeSwing.

2. If Exit is not included in the first function, then it completes the FindObstaclePipe function but keeps finding more TPA's and subsequently randomly clicking on the screen. It moves on to FindRopeSwing after the ropeswing comes on to the screen.

this isn't my final code of course, just a sort of example of what I want to do. So I guess my problem is understanding how to create a procedure to include these functions in a manner such that the FindObstaclePipe function finds the obstacle pipe, and clicks on it (which the function does), waits as you go through the tube, then ends that function and moves on to finding the ropeswing (FindRopeSwing).

It's probably a stupid question, I just am having problems wrapping my mind around how to create a procedure using these functions that does this simply and efficiently.

Help would be greatly appreciated-- and any tips on improving my TPA functions would also be nice!

nickrules
02-26-2012, 03:19 PM
*woo for TPAs! :p

I think I've found your problem:
For I := 0 To H Do
Begin

MiddleTPAEx(ATPA[I], X, Y);
MMouse(X, Y, 3, 3);
Wait(50 + Random(50));
If IsUpText('queeze') Then
Begin
Writeln('Found Obstacle Pipe!');
GetMousePos(X, Y);
MMouse(x, y, 3, 3);
Mouse(x, y, 0, 0, 1);
Result := True;
Wait(5000+random(2000));
Exit; //<------Problem
End;

end;

if you don't call exit, you won't break out of that loop, so it'll search until it runs out of points to check.

"Alright, but why doesn't it find the second object after that?"

Most likely because the second finder isn't actually finding anything ;) update the colors and check for any simple mistakes you made in it, and if you used ACA to get the colors (and set CTS to 2), make sure you set that up in your script.



----
While not related to your question, you don't need GetMousePos(X, Y);
MMouse(x, y, 3, 3);
Mouse(x, y, 0, 0, 1);

just call GetMousePos(X, Y);
//no mmouse(x,y,3,3); because your mouse is already on the object!
Mouse(x, y, 0, 0, 1);

NCDS
02-26-2012, 03:35 PM
Try and watch the names of the sub-forums and post in the correct one next time, please. This would go much nicer in a 'help' sub-forum, rather than tutorials.

putonajonny
02-26-2012, 03:37 PM
Let me know if you don't understand any of this

program new;
{$DEFINE SRL5}
{$i SRL/srl.simba}

Var
TP : TPoint; //TPoint to store the points in

Const
SwingColor = 0; //You need to set this
PipeColor = 0; //This too

function FindObstaclePipe(Var TP : TPoint): Boolean;
var
TPA : TPointArray;
i, x, y : Integer;
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, PipeColor, MSX1, MSY1, MSX2, MSY2, 15);
If Length(TPA) = 0 Then
Exit;
for i := 0 To high(TPA) do
begin
MMouse(TPA[i].x, TPA[i].y, 3, 3);
Wait(50 + Random(50));
If WaitUpText('queeze', 200+Random(200)) Then
begin
Writeln('Found Obstacle Pipe!');
ClickMouse2(mouse_Left);
GetMousePos(x, y);
TP := Point(x, y);
Result := True;
Wait(5000+random(2000));
Exit; //<------Problem
end;

end;
end;

function FindRopeSwing(Var TP : TPoint): Boolean;
var
TPA : TPointArray;
I, x, y : Integer;
Begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, SwingColor, 290, 8, 296, 55, 2);
If Length(TPA) = 0 Then
Exit;
For i := 0 To high(TPA) Do
Begin
MMouse(TPA[i].X, TPA[i].Y, 2, 2);
Wait(50 + Random(50));
If WaitUpText('wing-on', random(500)) Then
Begin
Writeln('Found Rope Swing!');
GetMousePos(X, Y);
ClickMouse2(mouse_Left);
TP := Point(x, y);
Result := True;
Exit;
End;
End;
End;


begin
SetUpSRL;
FindObstaclePipe(TP);
FindRopeSwing(TP);
end.

Archaic
02-26-2012, 11:07 PM
if you don't call exit, you won't break out of that loop, so it'll search until it runs out of points to check.

"Alright, but why doesn't it find the second object after that?"

Most likely because the second finder isn't actually finding anything update the colors and check for any simple mistakes you made in it, and if you used ACA to get the colors (and set CTS to 2), make sure you set that up in your script.



----
While not related to your question, you don't need
Simba Code:
GetMousePos(X, Y);
MMouse(x, y, 3, 3);
Mouse(x, y, 0, 0, 1);

just call
Simba Code:
GetMousePos(X, Y);
//no mmouse(x,y,3,3); because your mouse is already on the object!
Mouse(x, y, 0, 0, 1);

Thank you for the help Nick! I keep making silly little mistakes, I'll double check my color/setting in my auto color function for the Rope Swing.


Try and watch the names of the sub-forums and post in the correct one next time, please. This would go much nicer in a 'help' sub-forum, rather than tutorials.

Sorry about that! I saw a bunch of other questions in this sub forum so I thought it would be a good place. So much for following the crowd haha.


Let me know if you don't understand any of this

Yep that makes a lot of sense.:duh: I tend to forget that a TPoint is both an x and y coordinate which makes things a bit simpler. I think the only question I may have (which may be a slightly stupid question that I think I already know the answer to) is after declaring a variable as a TPoint, what changes do I need to make to any procedures that use the function with the variables set as integers and not as a single TPoint (i.e. if I call a function using TPoints in a procedure, do I need to change any other functions using X, Y integers over to TPoints as well in that procedure)? Thank you for your help! clever name by the way haha.