Jump to content
Macro Express Forums

the while loop


Recommended Posts

my question is simple, there is a a way to do a while loop in macro express pro ? it seem like i can't do it with macro express trough basic tools, maybe trough external script ? i want a while loop to check for two colors variables, each color in a specific area of the screen, while the two colors are detected, each on their respective area, execute something. 
Anyone can help me with that ? Thanks.

Link to comment
Share on other sites

Look at the Repeat instructions.  There is a "Repeat Until ...." that should do what you want. 

Though the logic might be easier if you use "Repeat Start...".  For example,

 

REPEAT START

IF COLOR1 = XXXX

   AND 

IF COLOR2 = YYYYY

   DO STUFF

ELSE

REPEAT EXIT

END IF

END REPEAT

Link to comment
Share on other sites

The problem I've had with UNTIL loops is the ease of getting into infinite loops. The workaround I use is to set a "failsafe" value for the maximum number of repeats. Sometimes this value is a guess -- e.g., 20 or 100 or 1000 should be enough -- and sometimes it's calculated -- e.g., the number of pixels between points A and B.

 

It's less efficient to introduce and keep track of a failsafe variable, but I find the technique leads to more reliable scripts.

Link to comment
Share on other sites

I do the same thing acantor does. It's sound advice.

Don't forget to include reasonable delay in the loop also. For things like this I find 100 ms, 10 times a second, adequate.

If a macro gets into an infinite or long running loop, don't forget you have a hotkey to abort macros. You can set it in preferences under the miscellaneous playback section. By default it's Win + End.

Link to comment
Share on other sites

3 hours ago, acantor said:

The problem I've had with UNTIL loops is the ease of getting into infinite loops.

 

Ah, but don't we all write intentionally-infinite loops (REPEAT UNTIL %X% IS NOT EQUAL TO %X%)?  We do that because REPEAT START does not have a REPEAT INDEFINITELY option.  But I agree -- it is always wise to explicitly limit the loop in case, heaven forbid, we commit an error in logic.  Also, I generally embed the same 1/10 second delays like Cory does, if it's a macro the user is waiting for.  Longer or shorter delays when waiting for the computer itself to finish doing something, when human perception is not involved. 

Link to comment
Share on other sites

Quote

 

Ah, but don't we all write intentionally-infinite loops (REPEAT UNTIL %X% IS NOT EQUAL TO %X%)? 

 

(Image of a deer caught in a headlight!)

 

I confess... I do this occasionally... but only when the speed penalty is too great.

 

I do for myself, but not for the macros I write for others. I know how to break out of an infinite loop, but my clients usually don't!

Link to comment
Share on other sites

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...
×
×
  • Create New...