Jump to content

Cleanest way to code multiple PixelGetColor?


Recommended Posts

Greetings everyone, I have done several searches in the help file, and on the internet, but could still use your help. I would like to check 6 different positions for a color(say 0xD79C4E), and if they are what I want then continue the script, if not then do something else. So what I'm thinking is instead of looking for a positive outcome of the color in the window, look for the absence of it, kind of like so:

$pixel1 = PixelGetColor(1, 1)
$pixel2 = PixelGetColor(2, 2)
$pixel3 = PixelGetColor(3, 3)
$pixel4 = PixelGetColor(4, 4)
$pixel5 = PixelGetColor(5, 5)
$pixel6 = PixelGetColor(6, 6)
 
If $pixel1 = 0xFFFFFF Then; If it's white then search failed
Exit
ElseIf $pixel2 = 0xFFFFFF Then; If it's white then search failed
Exit
ElseIf $pixel3 = 0xFFFFFF Then; If it's white then search failed
Exit
ElseIf $pixel4 = 0xFFFFFF Then; If it's white then search failed
Exit
ElseIf $pixel5 = 0xFFFFFF Then; If it's white then search failed
Exit
ElseIf $pixel6 = 0xFFFFFF Then; If it's white then search failed
Exit
Else
Do something here;Something other than white background at all positions, so carry on.

Would this be the cleanest way to code it, or is there a better way?

Thank you in advance for any and all replies.

EDIT: I know the code isn't totally kosher, but I just wanted to get the idea across.

Edited by bradacc
Link to comment
Share on other sites

What you do is right but maybe some personal opinions.

It seems more logical look for the positive results, but i dont have any idea in what you are working so maybe you are right...

Tell me this... the condition to exit the script is that All the pixels that you are looking for are not there?

You can use something like this if you want

$pixel1 = PixelGetColor(1, 1)
$pixel2 = PixelGetColor(2, 2)
$pixel3 = PixelGetColor(3, 3)
$pixel4 = PixelGetColor(4, 4)
$pixel5 = PixelGetColor(5, 5)
$pixel6 = PixelGetColor(6, 6)
If $pixel1 = 0xFFFFFF and $pixel2 = 0xFFFFFF and $pixel3 = 0xFFFFFF and $pixel4 = 0xFFFFFF and $pixel5 = 0xFFFFFF and $pixel6 = 0xFFFFFF Then exit
 
;Something other than white background at all positions, so carry on.

Or Replace the "And" for "Or" if that is the case.

This works too

$pixel1 = PixelGetColor(1, 1)
$pixel2 = PixelGetColor(2, 2)
$pixel3 = PixelGetColor(3, 3)
$pixel4 = PixelGetColor(4, 4)
$pixel5 = PixelGetColor(5, 5)
$pixel6 = PixelGetColor(6, 6)
If $pixel1 = 0xFFFFFF and _
$pixel2 = 0xFFFFFF and _
$pixel3 = 0xFFFFFF and _
$pixel4 = 0xFFFFFF and _
$pixel5 = 0xFFFFFF and _
$pixel6 = 0xFFFFFF Then exit
MsgBox(0,"ooh","you pass")
;Something other than white background at all positions, so carry on.
Edited by monoscout999
Link to comment
Share on other sites

Awesome! That looks way cleaner, thank you.

It would be "Or" instead of the "And".

I am looking for a name(in orange), if I find that name then I can continue with the script. If the name isn't where I thought it should be I will search in a different area.

I just couldn't think of how I should do an If statement with multiple positives. Thanks to your help I know now.

CHEERS!

Link to comment
Share on other sites

Select
Case PixelGetColor(1, 1) = 0xFFFFFF    
        Exit
Case PixelGetColor(2, 2) = 0xFFFFFF    
        Exit
Case PixelGetColor(3, 3) = 0xFFFFFF    
        Exit
Case PixelGetColor(4, 4) = 0xFFFFFF    
        Exit
Case PixelGetColor(5, 5) = 0xFFFFFF    
        Exit
Case PixelGetColor(6, 6) = 0xFFFFFF   
        Exit
Case Else   
Do something here;Something other than white background at all positions, so carry on.EndSelect

Thats probably the cleanest

Edited by gononono64
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...