Jump to content
Macro Express Forums

Repeat Loop For 30 Seconds


Recommended Posts

I see lots of options for repeating a loop within a macro.  But not a way to do it for a specific amount of time.

Suppose we want to repeat a loop for 30 seconds.  Then stop that loop, and continue onto the next part of the macro.

Can we do this?  How?

Thanks much!

Nicholas Kormanik

 

Link to comment
Share on other sites

I think the best you will be able to do is repeat an action x times, with a delay within the loop. You would have to experiment with the number of repeats and delays to take 30 seconds. A loop repeated 30 times with a one second delay would be a good place to start.

Link to comment
Share on other sites

Sure there is. It's called Repeat Until. Set a time variable value to 30 seconds in the future before the loop begins. Set the time in a second variable in the loop. Then use the "greater than" comparator. 

Link to comment
Share on other sites

3 hours ago, Cory said:

Sure there is. It's called Repeat Until. Set a time variable value to 30 seconds in the future before the loop begins. Set the time in a second variable in the loop. Then use the "greater than" comparator. 

Great idea!  Too easy! 

I tend to use acantor's technique, but of course that only approximates the duration.  In any case I think it's a good idea to have a delay inside the loop, even if a very short one, on the theory that the delay releases control to Windows so the computer can do something else during the REPEAT loop rather than just a CPU-bound loop.  Of course I don't know if that's how ME interacts with Windows, but I contend it's a good theory in any case. ?  For most "wait" loops I use 100ms as the delay, since 1/10 second is almost imperceptible to the user.  Additionally, a timed delay is independent of processor speed, so the macro will appear to run more-or-less the same on older vs. newer PCs. 

Link to comment
Share on other sites

This logic waits for up to approximately 20 seconds (200 tenths).  As soon as screen colors match the expected values, it exits from the REPEAT loop.  If colors do not match within 200 iterations, it also falls through the REPEAT END to whatever instructions follow. 

// wait 20 seconds for switch to password screen (monitor for change from blue to white, and for Submit button (gray))
   Repeat Start (Repeat 200 times)
    Get Pixel: Screen Coords: 600,565 into %N1%
    Get Pixel: Screen Coords: 268,466 into %N2%
    If Variable %N1% = 16777215
      AND
    If Variable %N2% = 13160660
      Repeat Exit
    Else
      Delay 100 Milliseconds
    End If
  Repeat End

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...