inter Posted March 11, 2011 Posted March 11, 2011 Hello all, I've run in to a problem that I'm sure I'm overlooking a simple solution to. I'm trying to PixelSearch for a couple of colors and if either of them is found execute a bit of code and I've got this part working no problem. Local $colors[2] = [ 0xB0BDCC, 0x899BCD ] For $i = 0 to 1 $b = PixelSearch(161, 298, 324, 321, $colors[$i], 20, 1) If IsArray($b) Then _Func1 EndIf Next However, the trouble I run in to is that I need to execute another bit of code if neither of the two colors is found. Local $colors[2] = [ 0xB0BDCC, 0x899BCD ] For $i = 0 to 1 $b = PixelSearch(161, 298, 324, 321, $colors[$i], 20, 1) If IsArray($b) Then _Func1() Else _Func2() EndIf Next The problem being that if the first color in my array isn't found it immediately executes _Func2() rather than searching for the second color first. I understand that as my code is written it's actually doing what I'm telling it to do, but I'm a bit unsure on how to fix my code to have it perform as I intend. Thanks in advance for any help provided.
Moderators Melba23 Posted March 11, 2011 Moderators Posted March 11, 2011 inter, I would do it like this: Local $colors[2] = [ 0xB0BDCC, 0x899BCD ] ; Clear flag Local $fFlag = 0 ; Run double search For $i = 0 To 1 $b = PixelSearch(161, 298, 324, 321, $colors[$i], 20, 1) ; If found then set flag If IsArray($b) Then $fFlag += 1 Next ; Now check flag If $fFlag Then ; Flag was set at least once _Func1() Else ; Flag was not set _Func2() EndIf There are many other ways, but I quite like flags! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
FastFrench Posted March 11, 2011 Posted March 11, 2011 Another way is this : Local $colors[2] = [ 0xB0BDCC, 0x899BCD ] #include "fastfind.au3" FFAddColor($colors) $b = FFNearestPixel(161, 298, 324, 321, 0, 0, -1) If IsArray($b) Then _Func1() Else _Func2() EndIf
inter Posted March 11, 2011 Author Posted March 11, 2011 Thank you both for your suggestions. Melba, I'm not sure how I get lucky to have you respond to my threads first, but you've always been able to get exactly what I need. Many thanks!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now