Results 1 to 10 of 10

Thread: SPS_WalkPath unnecessary delay in the end

  1. #1
    Join Date
    Feb 2007
    Location
    Switzerland
    Posts
    583
    Mentioned
    1 Post(s)
    Quoted
    50 Post(s)

    Default SPS_WalkPath unnecessary delay in the end

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

    Simba 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

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Feb 2007
    Location
    Switzerland
    Posts
    583
    Mentioned
    1 Post(s)
    Quoted
    50 Post(s)

    Default

    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
    Simba Code:
    T := GetSystemTime + 20000 + Random(5000);
    So it won't have a delay for walks shorter than 20+5 seconds.
    Last edited by Gala; 03-04-2012 at 07:51 PM.

  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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..
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Feb 2007
    Location
    Switzerland
    Posts
    583
    Mentioned
    1 Post(s)
    Quoted
    50 Post(s)

    Default

    Quote Originally Posted by ggzz View Post

    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.
    Simba Code:
    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.
    Simba Code:
    while (not Result) or (GetSystemTime < T) do
    Last edited by Gala; 03-04-2012 at 08:44 PM.

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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.
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Feb 2007
    Location
    Switzerland
    Posts
    583
    Mentioned
    1 Post(s)
    Quoted
    50 Post(s)

    Default

    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?

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    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:

    Simba Code:
    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:

    Simba Code:
    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.
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Feb 2007
    Location
    Switzerland
    Posts
    583
    Mentioned
    1 Post(s)
    Quoted
    50 Post(s)

    Default

    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)

  10. #10
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Gala View Post
    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).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •