Jump to content
Sign in to follow this  
Buntuu

while inside for

Recommended Posts

Buntuu

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

Share this post


Link to post
Share on other sites
Melba23

Buntuu,

Your logic was not entirely correct. :D 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
    
Next

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Buntuu

You suggest, that I need save all color positions from previous time?

In an array?

;$coord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $:D ; 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?

Share this post


Link to post
Share on other sites
Melba23

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

M23

Edit: You could start here.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Buntuu

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

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 by Buntuu

Share this post


Link to post
Share on other sites
Melba23

Buntuu,

Now I understand what you are trying to do (age, you know :D, 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 = @error

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.