Jump to content
Macro Express Forums

Recommended Posts

Hi guys, I'm a new member. I'm also pretty new to all this programming stuff. I did get down the basics of macro express through trial and error, but I couldn't figure out how to stop a repeat if a part of a screen did not contain a certain color pixel. Thank you very much for any help.

Oh and if all possible, can you explain each line so i can learn? Thanks again. :D :D

 

Edit: Now as a continuation of the searching a area for a pixel, what if i wanted it to search the entire screen for a pixel color in the middle of a repeat, and then click on that pixel?

 

Sorry for having a TON of questions, and thanks for answering them ALL :)

Share this post


Link to post
Share on other sites

Okay, say you are looking for pixel color 0 aka black

Set var %N1% to 0

Get pixel value into var %N2%

Do all the checking for the pixels

After each pixel check do a if %N2% equals 0 (black) then set %N1% to 1

Then after you check the pixels

If %N1% equals 1 end repeat

 

I am doing this on my phone so sorry for the brevity. Let me know if you have any questions

Share this post


Link to post
Share on other sites

In pseudocode:

Repeat Until %n1% not equal 0
 Get Pixel at location x, y into %n1%
End Repeat

The trick here will be to determine what values x and y should have each time you execute the Get Pixel command.

If the values of x and y remain the same, then this macro will simply run until the pixel located at x, y is no longer 0. If that pixel never changes, then your macro will run for ever!

If you want to move along a row of pixels, or down a column of pixels, then you need to add 1 to x or y respectively.

Share this post


Link to post
Share on other sites

In pseudocode:

Repeat Until %n1% not equal 0
 Get Pixel at location x, y into %n1%
End Repeat

The trick here will be to determine what values x and y should have each time you execute the Get Pixel command.

If the values of x and y remain the same, then this macro will simply run until the pixel located at x, y is no longer 0. If that pixel never changes, then your macro will run for ever!

If you want to move along a row of pixels, or down a column of pixels, then you need to add 1 to x or y respectively.

 

 

im not sure that would work...

 

say he was looking for color 0. say the first pixel he finds is 654321. that does not equal 0 and the macro would stop

he could repeat until %N1% = 0 but that would go in an endless loop if 0 is never found.

I think a boolean system like the one i suggested would work for him.

 

if i am wrong or misunderstanding your coding, please correct me. :)

Share this post


Link to post
Share on other sites

im not sure that would work...

 

say he was looking for color 0. say the first pixel he finds is 654321. that does not equal 0 and the macro would stop

But that was what was requested, n'est-ce pas?

... how to stop a repeat if a part of a screen did not contain a certain color pixel

Share this post


Link to post
Share on other sites

The possibility of an infinite loop is an inherent problem to the "Repeat Until" logic. It is an elegant and efficient loop, but if the test condition is not met, the script must be stopped manually. MEP error trapping for "Repeat Until" cannot prevent most infinite loops: Macro Express looks for a canceled dialog box, a non-existent path, an undefined variable, and that's all.

 

Increasingly, I add a "fail safe" mechanism when I use "Repeat Until."For example, I might do something like this to prevent infinite loops:

 

// Check each pixel along a vertical line from (5,0) to (5, screen height) for black (pixel color = 0)
//
// The VARIABLES
//
Set %N1% = Height of screen in pixels // Screen height count. (A fail-safe so "Repeat Until" won't repeat forever)
Set %N2% = -1 // Pixel Colour. (We are looking for 0, so start with a colour that does not exist)
Set %N3% = 5 // X-coordinate relative to screen
Set %N4% = 0 // Y-coordinate relative to screen
//
// The REPEAT LOOP
//
Repeat Until %N2% = 0 // Hunt for a black pixel 
 Move Mouse to %N3% %N4% relative to screen // X and Y
 Get Pixel Color at %N3% %N4% and store in %N2%
 //
 // The FAIL-SAFE: Prevent infinite loop by checking a finite number of pixels: the screen height
 //
 If %N1% = 0 Then
   // The entire vertical line has been checked. The pixel was not found!
   Stop
 End if
 %N1% = %N1% - 1 // Decrement the screen height counter 
 %N4% = %N4% + 1 // We will check the next Y coordinate on the next pass
Repeat End 
//
// The FINISH: The pixel was found, so do to next step

Share this post


Link to post
Share on other sites

But that was what was requested, n'est-ce pas?

 

 

 

what if the area he checks contains 25 pixels... 5x5

 

pixel 1,1 could be 123456 and the macro would stop... but pixel 1,2 is 0

the macro would have stopped before reaching the second pixel

 

 

 

 

@ funnyboy, either mine or Alans method would work. However, i recommend Alans... its a bit better because it will stop after finding the pixel... say there are 1000 pixels to check.. and number 250 is the black pixel you want.. it will stop at 250 while mine will check all 1000

 

although... if you add an if %N1% (the boolean) equals 1 end repeat that would stop it. So actually, in retrospect you have 2 ways to accomplish the same thing

Share this post


Link to post
Share on other sites

Wow, thanks guys, i got a LOT more help than i expected, but what if i want it to stop the repeat at a certain part of the repeat, if it doesn't detect a certain color pixel on a certain x,y coordinate on the screen? Would these repeat ends work if i stuck it in the middle of a repeat? What I wanted was actually a lot simpler, but I can actually use this too. My entire macro would be a repeat, and if at a certain point, there isn't a "black" pixel on the screen on a x,y coordinate, I want it to stop, even if this command is in the middle of the macro. Thanks for any additional help :)

 

Edit: Nevermind guys, i got most of it by taking apart the script that you guys gave me, but how do you set a variable before hand? Can't seem to find it in scripting editor. Thanks!

 

Edit: Does "<>" mean not equal to? What if i wanted it to stop when T1 does not equal T2 in the middle of a script?

Share this post


Link to post
Share on other sites
Would these repeat ends work if i stuck it in the middle of a repeat?

No. Use the Break command to terminate a repeat loop. Something like this:

If Variable %N1% <> variable %N2%
 Break
End If

how do you set a variable before hand?
Variable Set Integer %N1% to 10203040

 

Does "<>" mean not equal to?

Yes.

 

What if i wanted it to stop when T1 does not equal T2?

If Variable %T1% <> variable %T2%
 Break
End If

Share this post


Link to post
Share on other sites

So I can put the End If in the middle of a repeat, if I add a break, correct?

So i can do:

 

Set variable %T5% = 1
Repeat until %T5% = 0
Set variable %T2% = 1842479
Get Pixel: Screen coords 148,444 into %T1%
If Variable %T1% <> variable %T2%
 Break
End If
Mouse click pos 148,444
Repeat End

 

As a example, would this work? It would keep clicking on position 148, 444, until that positions pixel was no longer the pixel color 1842479?

And it would stop and not click on pos 148, 444, the moment the pixel turns into a different color?

 

Sorry for the double post >.<

 

Edit: NEVER MIND GUYS! I GOT IT WORKING PERFECTLY!!!! :) Thanks for all your contributions, it was all a learning experience... wait... need more help please >.< :) :) :) :)

 

Edit: Now as a continuation of the searching a area for a pixel, what if i wanted it to search the entire screen for a pixel color in the middle of a repeat, and then click on that pixel?

 

Sorry for having a TON of questions, and thanks for answering them ALL :)

Share this post


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