Sign in to follow this  
Followers 0
bradacc

Cleanest way to code multiple PixelGetColor?

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


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

Share this post


Link to post
Share on other sites

If you are looking for a string maybe there is more effective ways to do that.. If you are looking for an image there is another easy ways.. but if your method works.. go on :mellow:

Share this post


Link to post
Share on other sites

Slightly more complicated, but IMO cleaner

Dim $Pixel[2][6]=[[1, 2, 3, 4,5,6], [1, 2, 3, 4,5,6]]

for $l = 0 to 5

if PixelGetColor($pixel[0][$l],$pixel[1][$l]) = 0xFFFFFF Then

Exit

EndIf

Next

Beep(200,200)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0