vorg Posted July 10, 2021 Report Share Posted July 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
rberq Posted July 10, 2021 Report Share Posted July 10, 2021 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 Quote Link to comment Share on other sites More sharing options...
acantor Posted July 10, 2021 Report Share Posted July 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted July 10, 2021 Report Share Posted July 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
rberq Posted July 10, 2021 Report Share Posted July 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted July 10, 2021 Report Share Posted July 10, 2021 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.