Buntuu Posted January 17, 2010 Share Posted January 17, 2010 Hello there I run into a problem using arrays and loops for loop seems to work fine, but as soon it goes into while and return false it just quit maybe I didn't understand logic or maybe it is some program fault? here is the code fragment For $i=0 to $TreeCount -1 $b = $TreeColors[$i] $coord = PixelSearch( 0, 0, @DesktopWidth, @DesktopHeight, $b ) While Not @error $c = $c +1 $coord = PixelSearch( 0, 0, @DesktopWidth, @DesktopHeight, $b ) MouseMove($coord[0], $coord[1], 0) MouseDown("left") MouseUp("left") $aa = $coord[0]+10 $bb = $coord[1]+55 MouseMove($aa, $bb, 20) MouseClick("left") ToolTip($c, 200, 200, "Did it work?") Sleep(500) WEnd ToolTip("going to next tree", 200, 400) Sleep(2000) Next ;MsgBox(0, "Progress", "Success") ToolTip("Success!", 200, 200, "Did it work?") Sleep(5000) It works only for one color. ass soon it goes in the while loop and return false - program stops. It can be 3rd color, or 1st or last. work only for one. And it returns ToolTip("Success!", 200, 200, "Did it work?") only in cases when no colors found at all :/ some advise? Thanks Buntuu Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2010 Moderators Share Posted January 17, 2010 Buntuu,Your logic was not entirely correct. You need to use ContinueLoop if nothing is found, not While...WEnd.This should work:; Loop this many times For $i = 0 To $TreeCount - 1 ; Look for this value $b = $TreeColors[$i] $coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) ; If nothing found then continue with next colour If @error Then ; Perhaps a message here? ContinueLoop EndIf ; But if found $c = $c + 1 ;$coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) ; Why do the search all over again? You already have the coords from above ; And the rest of your code NextM23 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 Link to comment Share on other sites More sharing options...
Buntuu Posted January 17, 2010 Author Share Posted January 17, 2010 You suggest, that I need save all color positions from previous time? In an array? ;$coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $ ; Why do the search all over again? You already have the coords from above I used While Not @error because there is many trees and it need to find them all, not only one time Maybe I don`t understand all how it works. Please can you explain? ; Loop this many times For $i = 0 To $TreeCount - 1 ; Look for this value $b = $TreeColors[$i] $coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) ; If nothing found then continue with next colour If @error Then ; Perhaps a message here? ContinueLoop EndIf ; But if found $c = $c + 1 ;$coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) ; Why do the search all over again? You already have the coords from above ; And the rest of your code Next If I use this it will search for that each tree color only one - right? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2010 Moderators Share Posted January 17, 2010 (edited) Buntuu,Sorry, I did not realise you wanted to find more than one instance of the colour. I know very little about PixelSearch. Try searching the forum to find another bot thread (there are enough of them!) where this is discussed - it must be possible. M23Edit: You could start here. Edited January 17, 2010 by Melba23 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 Link to comment Share on other sites More sharing options...
Buntuu Posted January 17, 2010 Author Share Posted January 17, 2010 (edited) Buntuu, Sorry, I did not realise you wanted to find more than one instance of the colour. I know very little about PixelSearch. Try searching the forum to find another bot thread (there are enough of them!) where this is discussed - it must be possible. M23 Edit: You could start here. Pixel search works good, what dont work is loops while inside for By logic a=0 b=4 for a < b next this works - it moves numbers up while Not @error WEnd this also works - its loops until all found BUT for a<b while not @error wend next works only for number one or whatever (the first thing that goes into while loop) and then it just stops (exit program) Edited January 17, 2010 by Buntuu Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2010 Moderators Share Posted January 17, 2010 Buntuu,Now I understand what you are trying to do (age, you know , I can see that you have a major problem with the code as you have written it. @error is reset after EVERY command, so by the time you get to the bottom of your While..WEnd loop, the @error set by the PixelSearch line has long been overwritten. Perhaps if you stored the error immediately and then used that variable as the While..WEnd condition?Something along these lines:$coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) $iError = @error While $iError = 0 $c = $c + 1 $coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $b) $iError = @errorM23 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 Link to comment Share on other sites More sharing options...
Buntuu Posted January 17, 2010 Author Share Posted January 17, 2010 Just tried your suggestion - no success Link to comment Share on other sites More sharing options...
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