Jump to content
Macro Express Forums
nkormanik

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

 

Share this post


Link to post
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.

Share this post


Link to post
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. 

Share this post


Link to post
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. 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Good code.  Thanks!

But the desperately needed info is how to get TIME PASSED into a variable.  30 seconds.

Or time counts up to 30 seconds.  In a variable.

So far, can't find it.  Seems Macro Express Pro left it out.  Go figure.

 

Share this post


Link to post
Share on other sites

Variable Set Integer has options to load current hour or minute or second into variables.  

Also experiment with the Date and Date/Time commands. 

Share this post


Link to post
Share on other sites
5 hours ago, nkormanik said:

Plain sneaky.  What's it doing hiding there??

 

😮 I have been using ME for years and I still stumble onto hidden stuff like that. 

Share this post


Link to post
Share on other sites
On 7/14/2018 at 12:19 AM, nkormanik said:

Plain sneaky.  What's it doing hiding there??

 

RTFM. LOL. JK. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×