Results 1 to 9 of 9

Thread: How to stop a looping

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default How to stop a looping

    Hello guys!
    I just started scripting and after some tutorials, I was doing very well until I needed to search for a Bitmap. My problem is: my script continues looking for it again and again, even if it was found. The code I was mirroring was from a old but very good tutorial from MujaheD. The original code is:

    Code:
    var//means that these are variables
    x,y,Bitmap:integer;//x,y and ie are integers
    
    procedure DeclareBMPS;
    begin
    Bitmap := BitmapFromString(18, 15, 'z78DA655459926D2908DC92' + 
           '03027E32B9FF25756A9D57DDF1FA545486815E9221417BDA11E56' + 
           'C653142AA6DF393C6947CFAEAC035D3BD623693EAC376660CD927' + 
           'CF70E352A09601A9F6306B257853C523ADD79E647CDA04C959BB8' + 
           '515C58A9DA1E491BC2CD7E914D90FCD650A9F4B9BF3E8EC3B81B2' + 
           '790C51EF8336E5F57C8AC67EFEF7F65A1FC265E9ECB8F5A9A6678' + 
           '485A70AC10DAD483A830AB9C864F3EA73CAB4CE5D6837150D2365' + 
           '3DA632157632E95B07AB45FEB218187D2B30402FA360BFD9F52AE' + 
           '9BE722CFC7F1593597E4E1B2C62B60EC319C2E98889833262C7CA' + 
           '1D8AB3EDB0E6BE04F56860595960F92FD7C502A3CEB1A36251542' + 
           '1A09423847EA13BE4A302054C210955EB7E8BC72160C9C7A5E05D' + 
           '69A8FCCC54DDE4345267E8974B6CBEFD02CA38C03D276208E432C' + 
           '1D2830E4F763D7D14AA67E88B6E9BC567DB629D3E40A14EDCD49C' + 
           '81FBA13AE3961CC1EA0A877F81FFDCEB6504E5CC06CBC7855C2EC' + 
           'BF285BA1DCB4A280AB743D153486073FAE00D51E13C70D6DDA1C3' + 
           'FD6103A2ED99C865E2FD9F5CD663F9C948A00D41D70A155B5F2EF' + 
           '1580CBA1D4F51FFEACA81B7FEFE6276E8BC1E22E777D687F2EBFF' + 
           '0F0B8385E1E84C4CC141248F0532C0FB8D5C04F15BCD41EAB9809' + 
           'C1D4A939C90B926B4AD1BF68B880476465E7C95FF303E44C147E1' + 
           'D6E750CB33590B59FFCC237E8AF86F0C0348593D1853DDA11DD5D' + 
           '1966A0D147AB741C0FE17DAC3FD6E15C8C03E041650E1CD1A4865' + 
           'CBCB85918B221774E72155EF469D4D277438DDFCCD21F609FA1F2' + 
           'D27CA792EE27C6F26309EDDA3273D0BE13CF07EE30C39DF49B93B' + 
           'E7F5453F168CC2C38E677DD39E567EE70BC3E44F026041911E5EA' + 
           'EB6D70E9F745030A625EE49248695B5608170A1CF4EAE11770AE2' + 
           'EEB437779785C0BEEECE41CD1BB3F066C805338B6FC509022383B' + 
           '7727AC162D2143EC741A7127A80CC3E5588356CC2303B0BE110D6' + 
           '4DFBFBEFE7430C578D2E196B297608F6DA3E2E580C07523A18171' + 
           '1ECABC7824ACEAEE7ED07C59666EB60C1323FB49AD78148B07CE3' + 
           'FCEFFBE59A2550EFB83B4DEF6E6439C134B4C79C8E15114F6985E' + 
           'DDA1F8B3D9679FA3CD8EA84513960914440364E3BF50F89B57509' + 
           '');
    end;
    
    procedure ClickBMPS;
    begin
    wait(300+random(32))
    movemousesmooth(x,y)
    wait(32+random(16))
    clickmouse(x,y,true)
    end;
    
    
    Procedure FindBMPS;
    begin
    if(FindBitmap(Bitmap,x,y))then
    ClickBMPS;
    end;
    
    begin
    repeat
    wait(1300)
    DeclareBMPS;
    FindBMPS;
    until(false)
    end.

    If I change to "until(true)" the script only runs once. How can I make the "repeat" stops and jump for the next steps just after I find my bitmap? I tried something like "until FindBitmap(true)" but I am not very good with syntax since I just started, so it don't work. Could someone help me please?

  2. #2
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by gere11 View Post
    Could someone help me please?
    I have joined your Find and ClickBMP procedures together. Also I have changed them into a function rather than a procedure. This function results in a boolean (which means it is either true or false), so if it finds the BMP the function results true, or if it didn't find the BMP it results false.

    Then, you can see in your main loop at the bottom, if FindBMPS is true, then it will break out of the repeat...until loop and continue with the rest of your script.

    Simba Code:
    var
      Bitmap: integer;

    procedure DeclareBMPS;
    begin
    Bitmap := BitmapFromString(18, 15, 'z78DA655459926D2908DC92' +
           '03027E32B9FF25756A9D57DDF1FA545486815E9221417BDA11E56' +
           'C653142AA6DF393C6947CFAEAC035D3BD623693EAC376660CD927' +
           'CF70E352A09601A9F6306B257853C523ADD79E647CDA04C959BB8' +
           '515C58A9DA1E491BC2CD7E914D90FCD650A9F4B9BF3E8EC3B81B2' +
           '790C51EF8336E5F57C8AC67EFEF7F65A1FC265E9ECB8F5A9A6678' +
           '485A70AC10DAD483A830AB9C864F3EA73CAB4CE5D6837150D2365' +
           '3DA632157632E95B07AB45FEB218187D2B30402FA360BFD9F52AE' +
           '9BE722CFC7F1593597E4E1B2C62B60EC319C2E98889833262C7CA' +
           '1D8AB3EDB0E6BE04F56860595960F92FD7C502A3CEB1A36251542' +
           '1A09423847EA13BE4A302054C210955EB7E8BC72160C9C7A5E05D' +
           '69A8FCCC54DDE4345267E8974B6CBEFD02CA38C03D276208E432C' +
           '1D2830E4F763D7D14AA67E88B6E9BC567DB629D3E40A14EDCD49C' +
           '81FBA13AE3961CC1EA0A877F81FFDCEB6504E5CC06CBC7855C2EC' +
           'BF285BA1DCB4A280AB743D153486073FAE00D51E13C70D6DDA1C3' +
           'FD6103A2ED99C865E2FD9F5CD663F9C948A00D41D70A155B5F2EF' +
           '1580CBA1D4F51FFEACA81B7FEFE6276E8BC1E22E777D687F2EBFF' +
           '0F0B8385E1E84C4CC141248F0532C0FB8D5C04F15BCD41EAB9809' +
           'C1D4A939C90B926B4AD1BF68B880476465E7C95FF303E44C147E1' +
           'D6E750CB33590B59FFCC237E8AF86F0C0348593D1853DDA11DD5D' +
           '1966A0D147AB741C0FE17DAC3FD6E15C8C03E041650E1CD1A4865' +
           'CBCB85918B221774E72155EF469D4D277438DDFCCD21F609FA1F2' +
           'D27CA792EE27C6F26309EDDA3273D0BE13CF07EE30C39DF49B93B' +
           'E7F5453F168CC2C38E677DD39E567EE70BC3E44F026041911E5EA' +
           'EB6D70E9F745030A625EE49248695B5608170A1CF4EAE11770AE2' +
           'EEB437779785C0BEEECE41CD1BB3F066C805338B6FC509022383B' +
           '7727AC162D2143EC741A7127A80CC3E5588356CC2303B0BE110D6' +
           '4DFBFBEFE7430C578D2E196B297608F6DA3E2E580C07523A18171' +
           '1ECABC7824ACEAEE7ED07C59666EB60C1323FB49AD78148B07CE3' +
           'FCEFFBE59A2550EFB83B4DEF6E6439C134B4C79C8E15114F6985E' +
           'DDA1F8B3D9679FA3CD8EA84513960914440364E3BF50F89B57509' +
           '');
    end;

    Function FindBMPS: boolean;
    var
      x, y: Integer  // I have changed x and y to LOCAL variables (i.e. inside a function/procedure)
    begin
      if (FindBitmap(Bitmap, x, y)) then
      begin
        writeln('we found bitmap');
        wait(300 + random(32));
        movemousesmooth(x, y);
        wait(32 + random(16));
        clickmouse(x, y, true);
        result := true; // function results true if found bitmap
      end else
        writeln('we did not find the bitmap')
    end;


    begin
      repeat
        wait(1300)
        DeclareBMPS;
        if (FindBMPS = true) then
          break;   // if it finds the bitmap it will break out of this repeat..until loop
      until(false)
      //rest of your code here
    end.

  3. #3
    Join Date
    Nov 2011
    Posts
    1,268
    Mentioned
    17 Post(s)
    Quoted
    217 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    I have joined your Find and ClickBMP procedures together. Also I have changed them into a function rather than a procedure. This function results in a boolean (which means it is either true or false), so if it finds the BMP the function results true, or if it didn't find the BMP it results false.

    Then, you can see in your main loop at the bottom, if FindBMPS is true, then it will break out of the repeat...until loop and continue with the rest of your script.

    Simba Code:
    var
      Bitmap: integer;

    procedure DeclareBMPS;
    begin
    Bitmap := BitmapFromString(18, 15, 'z78DA655459926D2908DC92' +
           '03027E32B9FF25756A9D57DDF1FA545486815E9221417BDA11E56' +
           'C653142AA6DF393C6947CFAEAC035D3BD623693EAC376660CD927' +
           'CF70E352A09601A9F6306B257853C523ADD79E647CDA04C959BB8' +
           '515C58A9DA1E491BC2CD7E914D90FCD650A9F4B9BF3E8EC3B81B2' +
           '790C51EF8336E5F57C8AC67EFEF7F65A1FC265E9ECB8F5A9A6678' +
           '485A70AC10DAD483A830AB9C864F3EA73CAB4CE5D6837150D2365' +
           '3DA632157632E95B07AB45FEB218187D2B30402FA360BFD9F52AE' +
           '9BE722CFC7F1593597E4E1B2C62B60EC319C2E98889833262C7CA' +
           '1D8AB3EDB0E6BE04F56860595960F92FD7C502A3CEB1A36251542' +
           '1A09423847EA13BE4A302054C210955EB7E8BC72160C9C7A5E05D' +
           '69A8FCCC54DDE4345267E8974B6CBEFD02CA38C03D276208E432C' +
           '1D2830E4F763D7D14AA67E88B6E9BC567DB629D3E40A14EDCD49C' +
           '81FBA13AE3961CC1EA0A877F81FFDCEB6504E5CC06CBC7855C2EC' +
           'BF285BA1DCB4A280AB743D153486073FAE00D51E13C70D6DDA1C3' +
           'FD6103A2ED99C865E2FD9F5CD663F9C948A00D41D70A155B5F2EF' +
           '1580CBA1D4F51FFEACA81B7FEFE6276E8BC1E22E777D687F2EBFF' +
           '0F0B8385E1E84C4CC141248F0532C0FB8D5C04F15BCD41EAB9809' +
           'C1D4A939C90B926B4AD1BF68B880476465E7C95FF303E44C147E1' +
           'D6E750CB33590B59FFCC237E8AF86F0C0348593D1853DDA11DD5D' +
           '1966A0D147AB741C0FE17DAC3FD6E15C8C03E041650E1CD1A4865' +
           'CBCB85918B221774E72155EF469D4D277438DDFCCD21F609FA1F2' +
           'D27CA792EE27C6F26309EDDA3273D0BE13CF07EE30C39DF49B93B' +
           'E7F5453F168CC2C38E677DD39E567EE70BC3E44F026041911E5EA' +
           'EB6D70E9F745030A625EE49248695B5608170A1CF4EAE11770AE2' +
           'EEB437779785C0BEEECE41CD1BB3F066C805338B6FC509022383B' +
           '7727AC162D2143EC741A7127A80CC3E5588356CC2303B0BE110D6' +
           '4DFBFBEFE7430C578D2E196B297608F6DA3E2E580C07523A18171' +
           '1ECABC7824ACEAEE7ED07C59666EB60C1323FB49AD78148B07CE3' +
           'FCEFFBE59A2550EFB83B4DEF6E6439C134B4C79C8E15114F6985E' +
           'DDA1F8B3D9679FA3CD8EA84513960914440364E3BF50F89B57509' +
           '');
    end;

    Function FindBMPS: boolean;
    var
      x, y: Integer  // I have changed x and y to LOCAL variables (i.e. inside a function/procedure)
    begin
      if (FindBitmap(Bitmap, x, y)) then
      begin
        writeln('we found bitmap');
        wait(300 + random(32));
        movemousesmooth(x, y);
        wait(32 + random(16));
        clickmouse(x, y, true);
        result := true; // function results true if found bitmap
      end else
        writeln('we did not find the bitmap')
    end;


    begin
      repeat
        wait(1300)
        DeclareBMPS;
        if (FindBMPS = true) then
          break;   // if it finds the bitmap it will break out of this repeat..until loop
      until(false)
      //rest of your code here
    end.
    Correct me if I'm wrong but shouldn't the declare function lay outside the loop. Else you are just loading it up multiple times.

  4. #4
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by DemiseScythe View Post
    Correct me if I'm wrong but shouldn't the declare function lay outside the loop. Else you are just loading it up multiple times.
    Yes, it is also infinite. I tried to keep it simple so he could understand

  5. #5
    Join Date
    Nov 2011
    Posts
    1,268
    Mentioned
    17 Post(s)
    Quoted
    217 Post(s)

    Default

    Anyways, the changes the major did except that with this:

    Simba Code:
    begin
      DeclareBMPS; // Declare before the loop begins
      repeat
        wait(200 + Random(100)); // Small waits with randomness are fine.
      until FindBMPS or not LoggedIn; // When FindBMPS is true, it exits loop
      //rest of your code here
    end.

  6. #6
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    A "while" loop might be nice for this.

    Simba Code:
    while not findBMPs do wait(1000);

    Will cut it down to one line

  7. #7
    Join Date
    Nov 2011
    Posts
    1,268
    Mentioned
    17 Post(s)
    Quoted
    217 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    A "while" loop might be nice for this.

    Simba Code:
    while not findBMPs do wait(1000);

    Will cut it down to one line
    An interesting way for looking at it. Might actually use a stack of these for my walking.

  8. #8
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    A "while" loop might be nice for this.

    Simba Code:
    while not findBMPs do wait(1000);

    Will cut it down to one line
    Can't forget the failsafes.

    Have a TimeFromMark check in there to make sure it doesn't sit there for ever looking for a bitmap which no longer exists.

    Something like:

    Simba Code:
    var
      T : Integer;

    begin
      MarkTime(T);
      while not FindBMPs do
      begin
        Wait(1000);
        if (TimeFromMark(T) > 30000 ) then // Time is in ms. 30000ms = 30 seconds. Change it to whatever suits it best
          DoSomething;
      end;
    end;
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  9. #9
    Join Date
    Jul 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    I have joined your Find and ClickBMP procedures together. Also I have changed them into a function rather than a procedure. This function results in a boolean (which means it is either true or false), so if it finds the BMP the function results true, or if it didn't find the BMP it results false.

    Then, you can see in your main loop at the bottom, if FindBMPS is true, then it will break out of the repeat...until loop and continue with the rest of your script.

    Thank you very much for your help. I didn't knew that there was differences between "procedure" and "function", I was thinking that procedure was the function on this language (like I said, just started scripting, I dunno very much about programming).

    Thanks again!




    To all,

    Thanks for the replies and for the help. This script is not mine, is from a Bitmap tutorial made by MujaheD. I did some adjustments on my script, like the DeclareBMPS outside of the looping and a FreeBitmap after that. But I could figure out how to stop the looping when it was done. Thanks for the help!

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
  •