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!
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!