Results 1 to 3 of 3

Thread: findLoading() and waitForLoading();

  1. #1
    Join Date
    Jul 2014
    Location
    My computer
    Posts
    78
    Mentioned
    8 Post(s)
    Quoted
    21 Post(s)

    Default findLoading() and waitForLoading();

    These two functions involve finding the little "loading - please wait." screen that pops up in the corner when you load a new area. My connection isn't the best and my VM starts to lag a noticeable amount when I have 3+ clients open, so I made these to add to my scripts to help ignore the varying lag I have.

    Hope someone else finds it useful as well.

    Simba Code:
    (*
      findLoading()
      by: HKbotz

        Waits to find the small loading screen in the corner when entering new
        areas. Returns true if it finds the loading screen, otherwise returns false.

        -waitTime: time(in ms) to wait to find loading screen
        -tol: the tolerance to use when searching for loading screen bitmap

        usage:
          findLoading(5000);
          if (findLoading(5000, 15)) then
            writeLn('Found the loading screen in corner.');
    *)

    function findLoading(waitTime: integer; tol: integer = 10): boolean;
    var
      loadingBMP: integer;
      p: TPoint;
      timer: TTimeMarker;
    begin
      result := false;
      loadingBMP := BitmapFromString(29, 10, 'meJyTFROSpQ1ia7sgqWlEFaOA5g' +
            'BNg7BZ+u9T0VigaXiMFfQrZJr5nmHRfyAJZCPrAgoCEV/iBLhiIBs' +
            'iCHQqHmNFrQPhfoGEElAEbjKEAbROWl4J4gCu4g0QQSADj7EctQfg' +
            '5kBsgWsEGgKUhbgNogtZMZCBx1igIcKuiXAukA0xlj+8EcgQN3JEj' +
            'mjijUWWhSiAaASaALEOqB7uWlyBALQX4ikIQosyIIK7HOhOiAhQL1' +
            'AW7higaRBxoL3IkUJ1BAAtAqT9');
      timer.start();
      repeat
        if (findBitmapToleranceIn(loadingBMP, p.x, p.y, mainscreen.getBounds(), tol)) then
        begin
          print('Found loading screen.');
          freeBitmap(loadingBMP);
          exit(true);
        end;
      until (timer.getTime() >= waitTime);
      print('Couldn''t find loading screen.');
      freeBitmap(loadingBMP);
    end;


    (*
      waitForLoading()
      by: HKbotz

        Finds loading screen, then waits for it to disappear. Returns true if it
        was able to find the loading screen and wait for it to disappear again,
        otherwise returns false.

        -findWait: time(in ms) to wait to find loading screen
        -waitTime: time(in ms) to wait for loading screen to go away
        -tol: the tolerance to use when searching for loading screen bitmap

        usage:
          waitForLoading(5000, 5000);

          if (waitForLoading(5000, 5000)) then
            writeLn('Loaded new aread.');
    *)

    function waitForLoading(findWait, waitTime: integer; tol: integer = 10): boolean;
    var
      timer: TTimeMarker;
    begin
      result := false;
      if (findLoading(findWait, tol)) then
      begin
        timer.start();
        repeat
          print('Waiting for loading screen to go away...');
          if (not findLoading(0, tol)) then
          begin
            print('Can''t find load screen anymore, must have loaded.');
            print('Time it took: ' + intToStr(timer.getTime()));
            exit(true);
          end;
        until (timer.getTime() >= waitTime);
      end;
      print('Never found loading screen.');
    end;
    Last edited by HKbotz; 12-30-2014 at 01:36 PM.

  2. #2
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    Good stuff, thanks for sharing!

  3. #3
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Wow, now that is really clever. I've never even though of this.

    Y'know when you see an ad on TV for something you didn't know existed, but desperately need? Yeah, that's this.

    Thanks for the share!
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

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
  •