SRL Archive - SRL Positioning System

SPS_WalkPath unnecessary delay in the end


Gala

2012-03-04 14:28:13

I wondered why SPS_WalkPath(); generates a little delay after the walk is done. I added the commented Break;. So here is the code:

// Walks the path "Path"; always walks to the furthest point possible
function SPS_WalkPath(Path: TPointArray): boolean;
var
I, H, T, D: integer;
P, MM: TPoint;
begin
H := High(Path);
T := GetSystemTime + 20000 + Random(5000);
while (not Result) and (GetSystemTime < T) do
begin
RunEnergy(20);

P := SPS_GetMyPos;
for I := H downto 0 do
begin
MM.X := MMCX + Path[I].X - P.X;
MM.Y := MMCY + Path[I].Y - P.Y;

D := Distance(MM.X, MM.Y, MMCX, MMCY);

if (D < 10) then
break
else begin
if (D < 70) then
begin
MouseFlag(MM.X, MM.Y, 0, 0, Integer(I<>H)*15);
T := getSystemTime + 20000 + Random(1000);
Break;
end;
end;
end;
Result := (I = H);
// Break;
end;
end;

In my script there is a very short path (Edgeville Bank -> Yews), so there is a delay of 10 sec after every walk.
I think the function can be broken after the last point is reached.

Nothing big, but very annoying for short walks. :)
(I saw it isn't fixed in SPS 1.5 either)

- Gala

Brandon

2012-03-04 14:38:43

Iunno how that'll fix it :S

The problem is this: (Integer(I<>H)*15)

That will wait until dist < 15 from the flag to click.. two choices there.. if I = H then FlagDist = 15.. if I<>H then flagdist = 0..

so it ends up doing the wait there.. It's how close u wanna be to the flag before exiting.. see MouseFlag function.

Gala

2012-03-04 14:48:58

No this is not the problem, Break is after Result = True.
Therefore, it is called when the path is walked. So I think it has nothing to do with the flag distance. Without Break, it just sits there for 10 seconds. (on the last TPoint). For me it fixed the problem.

Edit: Or we could lower the value of T
T := GetSystemTime + 20000 + Random(5000);
So it won't have a delay for walks shorter than 20+5 seconds.

Brandon

2012-03-04 15:23:47

no… i think ur mis-understanding how the function works..

First it checks your distance from the furthest point it can find in ur array of points..

then if the distance is < 10.. it will exit the entire function and return true.. allowing u do do whatever u want without waiting 20-25 seconds..

Next thing it does is if ur distance is > 10 then it will start walking to the position using mouseflag with a distance from the flag.. then it loops around again and checks the dist from the furthest point that is on the mm from you.. and checks the if dist < 10 again..

this is how sps walks the array of points.. ur break doesn't do anything but mess it up..

if sps is waiting 10 seconds for u for every walk.. then ur points in the tparray are bad or not found 100% of the time.

P.S. it gives itself 25 seconds to walk to keep trying to walk to your point if not already there..

Gala

2012-03-04 15:33:45

From: ggzz


P.S. it gives itself 25 seconds to walk to keep trying to walk to your point if not already there..


It think this could be the point. It gives itself 25 seconds no matter if it is there or not. So if it walks a path shorter than 25 seconds (in my case around 8 seconds), it waits for nothing. But it could break the while-loop instead of waiting 25-"WalkingTime" seconds.
while (not Result) and (GetSystemTime < T) do 

correct me if I am wrong.

Edit: I think this would also work, but not break the 'failsafe' function of the while loop.
while (not Result) or (GetSystemTime < T) do 

Brandon

2012-03-04 15:47:28


if (D < 70) then
begin
MouseFlag(MM.X, MM.Y, 0, 0, Integer(I<>H)*15);
T := getSystemTime + 20000 + Random(1000);
Break;
end;
Only gives itself a timer if ur far from the point.. 10 < D < 70 is the safe zone.. if not then the timer starts.. if u happen to get closer to the point within the 25 second time limit then it'll break out of the entire function IF dist < 10 from the last point in your array.

Gala

2012-03-04 15:59:54

Hmm, ok seems logical.
But for me it keeps repeating the while loop even if result is true.
The only thing that helped was the break;.

Why isn't it a good solution to break the while loop if result gets true OR the timer counted down?

Brandon

2012-03-04 16:15:30

The loop says "While NOT result or NOT timer ran out"

you have right after it checking the result, regardless of whether it's true or false.. you break out of the loop.

I expect that loop to run only once and walk one point.

it's like doing:


while (Not BankOpen) do
begin
//open bank
break; <-- doesn't even check to see if the bank is open first before breaking.. Just breaks
end;

//withdraw food.. Now it tries to withdraw food and messes up because it thinks the bank is already open since u broke out regardless of the result.

Might as well turn that entire loop above to:


if (Not bankopen)
openbank;

withdraw.. <-- again it doesn't even check if the bank is open.. with a break like that, there is no point to the while loop.

Gala

2012-03-04 16:27:39

I think I understood the while loop.
But it says "While NOT result AND NOT timer ran out"..
So even if the path is done, it waits for the timer ran out(?)

Is there another solution to break the function when the path is done? (and i mean to break it instantly)

Coh3n

2012-03-26 19:06:53

From: Gala
I think I understood the while loop.
But it says "While NOT result AND NOT timer ran out"..
So even if the path is done, it waits for the timer ran out(?)

Is there another solution to break the function when the path is done? (and i mean to break it instantly)
It means that the result has to equal false AND the timer hasn't run out. It will break out of the loop if one of those conditions isn't met.

In other words, as soon as the result is set to true, it will break out of the loop. I think the delay at the end had something to do with IsMoving being called somewhere. I've been testing 2.0 and it definitely doesn't happen, so I'm going to call this resolved (I'm making a new thread for the new version soon).