Results 1 to 5 of 5

Thread: Not digging the double loop... Suggestions?

  1. #1
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Not digging the double loop... Suggestions?

    Pretty much what the title says. Not really happy with this double loop. Any thoughts?

    Code:
    procedure StartBattle();
    var
        findDTMResultOne, findDTMResultTwo: Boolean;
        x1, y1, x2, y2, repeatCounter, failSafe: Integer;
    begin
        findDTMResultOne := FindDTM(DTMFromString(startButtonDTMString), x1, y1, GSX1, GSY1, GSX2, GSY2);
        Mouse(x1, y1, 0, 0, mouse_Left);
    
        // Outer loop with fail safe
        failSafe := 0;
        repeat
            // Inner loop checking if fight has started
            repeatCounter := 0;
            repeat
                Wait(150);
                Inc(repeatCounter);
                findDTMResultTwo := FindDTM(DTMFromString(fightStartedDTMString), x2, y2, GSX1, GSY1, GSX2, GSY2);
            until ((findDTMResultTwo = true) or (repeatCounter > 50));
            Inc(failSafe);
        until((findDTMResultTwo = true) or (failSafe > 3));
    
        if ((findDTMResultTwo = false) or (failSafe > 3)) then
            ThrowErrorAndTerminate('Error starting the fight');
    end;

  2. #2
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Simba Code:
    procedure StartBattle();
    var
      x, y, t: integer;
    begin
      if FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2) then
        Mouse(x, y, 0, 0, mouse_Left); {after 1 attempt of trying to find the dtm,
        if it's found on the first and only try, it will be left-clicked.}


      while (not(FindDTM(DTMFromString(fightStartedDTMString), x, y, GSX1, GSY1, GSX2, GSY2))) do
      begin
        wait(100);
        if (timefrommark(t)>10000) then
          exit; {this while .. do loop will repeat waiting 100 ms until 10000 ms,
          aka 10 seconds have passed or until the FindDTM is Found to be true. if it
          remains unfound for >10000 then it will exit the currecnt procedure.}

      end;
    end;
    Just a thought, don't know exactly what's going on, but perhaps this may help.

  3. #3
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thank you for the suggestion Le Jingle

    Here is where I was going and ended up

    Code:
    procedure StartBattle();
    var
        x, y, failSafe: Integer;
        loopRuntime: Integer;
    begin
        // Find and click the start button
        FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2);
        Mouse(x, y, 0, 0, mouse_Left);
    
        Wait(1500);
        failSafe := 0;
        MarkTime(loopRuntime);
        while (not(FindDTM(DTMFromString(fightStartedDTMString), x, y, GSX1, GSY1, GSX2, GSY2))) do
        begin
            // While the fight started DTM is not found wait 150 ms and try again
            Wait(150);
    
            // If we have waited 10 seconds and the fight hasn't started
            if (TimeFromMark(loopRuntime) > 10000) then
            begin
                // Reset the timer and increment the failSafe counter
                MarkTime(loopRuntime);
                Inc(failSafe);
    
                // If we have waited 10 seconds twice then something is wrong
                if (failSafe > 1) then
                    ThrowErrorAndTerminate('Error Starting Fight');
    
                // If the start button is found click it
                if (FindDTM(DTMFromString(startButtonDTMString), x, y, GSX1, GSY1, GSX2, GSY2)) then
                    Mouse(x, y, 0, 0, mouse_Left);
            end;
        end;
    end;

  4. #4
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    You should load your DTMs to a variable so you can free them. That procedure there will hog memory really fast.

  5. #5
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    You should load your DTMs to a variable so you can free them. That procedure there will hog memory really fast.
    Wow big oversight. Thanks for pointing that out. Fixed now

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
  •