Pixel Recognition and Loop

Hello, hope you are well.

I am wondering if I have written the best possible macro, as I don't have the best output.

My macro (below) consists in a screen orange pixel recognition that will trigger an other macro, and that is itself triggered by an other one previously (along with an other green pixel recognition macro, running simultaneously and looking for a green pixel in order to trigger some other macro).

The pixel recognition works fine for the orange and green pixel each time I trigger the macros with the hot key, otherwise it works irregularly if not to say randomly. It feels like if I have to "refresh" it with the hot key...

Is there a better way to write it ?

It is unclear what you are trying to do, but whatever it is those actions are unlikely to do it!

Cancel This Macro will stop the macro running, so the loop will never loop.

And Retry This Loop will never do anything because its not within a loop (unless this macro itself is called within a loop via an Execute a Macro action?).

So essentially if you press ⌘D, this macro will execute, and if the pixel is orange, will display the text and execute the tp 11 macro, and if the pixel is not orange will do nothing.

Yes, that is what I want to do, but without having to press ⌘D, I would like the macro to monitor the screen by itself (loop ?) and moves on only if it finds the orange pixel

For me cancel the macro was a way to stop the loop when orange pixel was found ; I was relying on the last "retry this loop" to loop but I may be wrong

Following your remarks, I will try this and make some test tomorrow

You cannot do this, there is no trigger for when the screen changes.

You could trigger a macro, and then have it loop and wait until the pixel is orange using the Pause Until action, and then perform the desired task, or use the While action and test if the pixel is orange and decide whether to execute the macro each time around. But that will be quite CPU/Battery/Energy intensive.

Again, the Retry action will do nothing unless it is within the loop.

Perhaps explain what you are actually trying to do?

Thank you, basically I want to click "ok" on a button on a website when it turns orange (from blue) and quickly execute a macro following.

" there is no trigger for when the screen changes"
---> I thought the while was a trigger by itself :S ^^

"have it loop and wait until the pixel is orange"
" Again, the Retry action will do nothing unless it is within the loop"
----> How can I loop I don't know how to do it :man_shrugging:

One thing I don't understand (additionnally !) is that in my both writings, it seems there is still a kind of loop ? because when I trigger it whith hot key, then recognition works. See one of my test (area of recognition is low / right) :

So, after many tries I've found where is my pb.

Unexpectedly the " IF orange pixel THEN execute (..) otherwise retry loop" macro above works fine as a loop (without cpu or ram workload).

But the reason why I've observed a random result is because I call two pixel recognition macros this way :


MAIN macro
..
..
..
Execute Orange pixel recognition macro (see screen shot above)
Execute Green pixel recognition macro (same as above but for green pixel)
..
..
End of MAIN macro

My pb was that the green macro, coming after, couldn't execute properly unless the orange macro before had found the orange pixel, and conversely if green macro were about to be written before the orange one (I've made different tests)

I didn't know that the order of executing was assuming : 1/ complete orange recognition then 2/ go for green recognition (and conversely if order was different)

So my question : what kind of trick can I use to execute both of those recognition macros simultaneously (or at least without waiting for one another) ?

Exactly the same -- as in checking the same pixel?

It isn't what most people would call a "loop" -- it's a side-effect of the "Retry" action when used in a "child" macro or subroutine. That "child" or subroutine is itself considered to be the loop and it starts again from the top, reinitialising local variables (I think), but it is still the same instance (the Executing Instance UUID doesn't change).

The more usual way to do what you are doing would be to "Pause Until" the pixel is the colour you want, then do the thing you've been waiting for. It's generally more efficient, though there's probably not much difference in this case because you have no variables and the child macro is so short.

The "trick" would be to set the child macros to run "Asynchronously" in the parent macro's calling action. But before you do that there's a potential for a lot of unintended consequences! Especially since you seem to have a "Main" macro that is calling the macro you've posted as a screenshot, which is itself calling another macro...

If you describe more fully what you are trying to do someone might come up with a more logical workflow -- especially if you actually are checking the same pixel in both "child" macros.

OK, so trigger your macro, and then start with a Pause Until action to pause until the pixel is orange, and then follow that with the rest of your macro (or an Execute a Macro action).

Ok well noted about the "pause until" function, thx

Thank you very much for you answer

Exactly the same -- as in checking the same pixel?

No, in fact theres is one macro (that you call child / subroutine) that is about to looking for the change of state of a button into orange (orange pixel), ant the other that is looking for the change of a number into green (green pixel). So it's different pixel that are monitored.

Both child macro are independent and trigger other different macros to complete task when recognition (orange or green) is done.
As you can see in my writing I made the child macro to cancel themselves when recognition is done to preserve CPU and RAM (I can also make those child macro to cancel one another If needed when recognition, because if green is recognized then I don't need the orange recognition anymore and conversely)

The main macro is just here to launch the gaming app and child macros (orange and green recognition) to react to its behavior the way I want.

It isn't what most people would call a "loop" -- it's a side-effect of the "Retry" action when used in a "child" macro or subroutine. That "child" or subroutine is itself considered to be the loop and it starts again from the top

Thank you very much for those explanations, now I understand why my writing was finally kind of "right" :slight_smile:

The more usual way to do what you are doing would be to "Pause Until" the pixel is the colour you want, then do the thing you've been waiting for. It's generally more efficient, though there's probably not much difference in this case because you have no variables and the child macro is so short

Yes I don't have any variable here, I can still make a try with the "Pause until"

The "trick" would be to set the child macros to run "Asynchronously" in the parent macro's calling action.

Yes you understand what I'm looking for now.

I don't want those child macro to be called in chronological order (for example 1/ orange child macro 2/ green child macro) in the parent macro, as it will result in first waiting for the orange child macro to complete orange recognition and THEN launching green recognition, while I need them to run IN THE SAME TIME to react accordingly to game change (what you called asynchronously)

So, to sum it up, can someone tell me how to launch 2 macros (or to be more precise 2 child macro from 1 parent macro) in the same time ? (to have both green and orange pixel recognition working in the same time)

I add that there isn't any unintended consequences (as your mentioned) because I've made several test launching them manually quite in the same time triggering their respective "hotkeys" and it works fine.

(attached documents : writing of the orange pixel recognition child macro - green is the same -, and how they are called from the parent macro)


parent and child macro structure

As said above...

The "trick" would be to set the child macros to run "Asynchronously" in the parent macro's calling action.

You probably only need one child macro with a "Pause Until... any of the following are true" and a condition for each pixel check, that then branches dependent on which it is. I don't really see a need to launch yet another macro after the pixel check, just roll those actions into the first child, but if you do spawn other macros you should probably run those asynchronously too.

Thank you very much Nige, I was just understanding what you said previously and finding the asynchronous menu, when I saw your last message.
I'm pretty sure this is what I'm looking for ! Eager to make new test soon

Thx again :pray: