Jump to content

Pixel Search usage help


Recommended Posts

I am trying to use the pixel search function to search for any 1 of 4 colors. It doesnt matter which one it comes across first. I am not sure what the best way to go about it is. If i use 4 lines of PixelSearch then it will just hop from one to the next before it does an action. I considered doing the folowing.

$Array[0] = xxxxxxxx     ;store the 4 values in an array
$Array[1] = xxxxxxxx
$Array[2] = xxxxxxxx
$Array[3] = xxxxxxxx

While 1
        $TCoord = PixelSearch (75, 150, 950, 600, $Array[$Count])
        If @error Then
            If $Count = 3 Then
                $Count = 0
            EndIf
            $Count + 1
            Return
        ElseIf Not @error Then
            $Count = 0
            Call ("Function")
        EndIf
    WEnd

I am not sure this will even work. I am still learning this so i may even have done some code wrong i am still working on it. Hopefully you can get an idea of what i am trying to do. Any help and suggestions would be greatly appreciated.

Link to comment
Share on other sites

This is a perfect fit for a For...Next loop, instead of a While loop:

$Array[0] = xxxxxxxx;store the 4 values in an array
$Array[1] = xxxxxxxx
$Array[2] = xxxxxxxx
$Array[3] = xxxxxxxx

For $count=0 To 3
    $TCoord = PixelSearch (75, 150, 950, 600, $Array[$Count])
    If NOT @error Then
        Function()
        ExitLoop
    EndIf
Next

The key to getting it to work is the ExitLoop line, which allows it to continue without checking for the other colors, if one is found. And, unless there's more to the code that dictates it, you don't have to use Call() to run a function in this way- just type in the function name and () after it to run it. Call() is usually used when the name of the function is stored in a string or variable or similar.

Other than that, the only real error I see in my cursory glance over your code is that your $Count + 1 line should be $Count+=1

Hope that's what you were looking for

Hope that helps

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

This is a perfect fit for a For...Next loop, instead of a While loop:

$Array[0] = xxxxxxxx;store the 4 values in an array
$Array[1] = xxxxxxxx
$Array[2] = xxxxxxxx
$Array[3] = xxxxxxxx

For $count=0 To 3
    $TCoord = PixelSearch (75, 150, 950, 600, $Array[$Count])
    If NOT @error Then
        Function()
        ExitLoop
    EndIf
Next

Other than that, your $Count + 1 line should be $Count+=1

Hope that helps

Thanks for the help. Right as you were posting i was doing more searching and found a thread with a little info but not much. So i rewrote it and it suggested the For Next thing as well. This is what i have now:

$Colors[4] = [0x15100A, 0x553826, 0x46332B, 0x7D5A45]
    For $X = 0 to Ubound($Colors) - 1
        $TCoord = PixelSearch ( 75, 150, 950, 600, $Colors[$X], 10)
    Next

The more i look at it tho i am wondering, will this pick 1 of the 4 colors and move on or will this wait till it finds all 4 then move on? thx for any help

Edited by Physical
Link to comment
Share on other sites

Thanks for the help. Right as you were posting i was doing more searching and found a thread with a little info but not much. So i rewrote it and it suggested the For Next thing as well. This is what i have now:

$Colors[4] = [0x15100A, 0x553826, 0x46332B, 0x7D5A45]
    For $X = 0 to Ubound($Colors) - 1
        $TCoord = PixelSearch ( 75, 150, 950, 600, $Colors[$X], 10)
    Next

The more i look at it tho i am wondering, will this pick 1 of the 4 colors and move on or will this wait till it finds all 4 then move on? thx for any help

Check my edit...look at ExitLoop :)
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Check my edit...look at ExitLoop :)

Ok yes this is helping a lot, thankyou very much. I have one more question. Would it be better to use the method of $Count = $Count + 1 to incriment the array or is the UBound function a better method? thx very much for your help

Link to comment
Share on other sites

The problem with PixelSearch is it gives the first pixel found.. from left to right, top to bottom.. don't forget this.

Thanks i didn't think about that. I will adjust it so it doesnt find the wrong thing.

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...