RichardAR Posted August 15, 2009 Share Posted August 15, 2009 The following function works however even when $f is false, the do until loop continues on. I am not sure if this is a bug with the Do/Until block or something I'm doing wrong. FYI, I have it set up so $f is always False, and isColorMatch is always True in the application I'm testing this on. Func somefunc() $f = False Do MouseClick("left", 748, 176, 1, 5) Sleep(500) Do $tc = PixelGetColor(1013, 256, $Hwnd) $ps = PixelSearch(748, 176, 761, 266, 0xFFFF00, 0, 1, $Hwnd) $f = IsArray($ps) If Not $f Then Send("{DOWN 5}") Sleep(500) EndIf Until $f Or IsColorMatch($tc, 0xB5B7B9, 10) If $f Then ConsoleWrite("f = true" & @CRLF) MouseClick("left", $ps[0], $ps[1], 1, 5) Sleep(500) MouseClick("left", 793, 77, 1, 5) Sleep(3000) While IsSomeFunc() Sleep(3000) WEnd MouseClick("left", 825, 77, 1, 5) Sleep(20000) Else ConsoleWrite("f = false" & @CRLF) EndIf Until ($f == False) EndFunc Link to comment Share on other sites More sharing options...
martin Posted August 15, 2009 Share Posted August 15, 2009 The following function works however even when $f is false, the do until loop continues on. I am not sure if this is a bug with the Do/Until block or something I'm doing wrong. FYI, I have it set up so $f is always False, and isColorMatch is always True in the application I'm testing this on. Func somefunc() $f = False Do MouseClick("left", 748, 176, 1, 5) Sleep(500) Do $tc = PixelGetColor(1013, 256, $Hwnd) $ps = PixelSearch(748, 176, 761, 266, 0xFFFF00, 0, 1, $Hwnd) $f = IsArray($ps) If Not $f Then Send("{DOWN 5}") Sleep(500) EndIf Until $f Or IsColorMatch($tc, 0xB5B7B9, 10) If $f Then ConsoleWrite("f = true" & @CRLF) MouseClick("left", $ps[0], $ps[1], 1, 5) Sleep(500) MouseClick("left", 793, 77, 1, 5) Sleep(3000) While IsSomeFunc() Sleep(3000) WEnd MouseClick("left", 825, 77, 1, 5) Sleep(20000) Else ConsoleWrite("f = false" & @CRLF) EndIf Until ($f == False) EndFunc I think it's just a question of understanding that the number 0 does not equate exactly to False. If $ps is not an array then $f = IsArray($ps) results in $f = 0 0 is a number not a boolean variable, and == tests for the variable type as well as the contents. so if $f has the value of zero then $f = false; would be true $f == False; would be false You could end your Do/Until with Until $f = False OR Until Not $f Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2009 Moderators Share Posted August 15, 2009 RichardAR,Although it is difficult to be sure from just a small snippet of a full script like this, it looks to me as if there is a problem with the logic flow of your code.There seems to be no way to reset $f to False once it is found to be True in the Inner Loop. So if $f is set to True there (quite likely given that it is one of your tests for exit!) there is no way it will ever satisfy the exit condition for the Outer Loop, which is why you never fall out of the Loop.Try resetting $f to False each time you enter your Inner Loop. That way you are giving your Outer Loop exit condition a chance to be met.I would strongly recommend that you write down a logic flow diagram for this section of your code and make sure that it is indeed acting as you want it to. Having nested loops with similar (and multiple) exit conditions can lead to some confusion in what result exactly is causing the loop to exit, or not!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 Link to comment Share on other sites More sharing options...
martin Posted August 15, 2009 Share Posted August 15, 2009 RichardAR,Although it is difficult to be sure from just a small snippet of a full script like this, it looks to me as if there is a problem with the logic flow of your code.There seems to be no way to reset $f to False once it is found to be True in the Inner Loop. So if $f is set to True there (quite likely given that it is one of your tests for exit!) there is no way it will ever satisfy the exit condition for the Outer Loop, which is why you never fall out of the Loop.Try resetting $f to False each time you enter your Inner Loop. That way you are giving your Outer Loop exit condition a chance to be met.I would strongly recommend that you write down a logic flow diagram for this section of your code and make sure that it is indeed acting as you want it to. Having nested loops with similar (and multiple) exit conditions can lead to some confusion in what result exactly is causing the loop to exit, or not!M23I don't think that is quite correct.I assume that the OP has seen that $f is 'false' from his ConsoleWrite lines. This will happen if in the inner loop $tc is an array but $ps is not. Then $f will be 0 and as I said, it won't pass the test $f == False at the end.Once the condition at the end of the outer loop fails the whole loop starts again so it will continue until $f is 0 (once the condition is corrected). So I think the only thing wrong with the code shown is the "==". Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2009 Moderators Share Posted August 15, 2009 martin, 15-0. >_< 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 Link to comment Share on other sites More sharing options...
martin Posted August 15, 2009 Share Posted August 15, 2009 martin,15-0. M23Maybe just net service >_< Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
RichardAR Posted August 16, 2009 Author Share Posted August 16, 2009 The problem was the outer loop, not the inner one. There should not have been a difference between = and == in a boolean statement with autoit; I try to use == so there is no confusion. This is what I did to fix the problem and now it works perfectly. Thanks for every one's input. Func SomeFunc() ;ProcessSetPriority("AutoIt3.exe", 3) ; this speeds things up considerably $f = True While $f Do $ps = PixelSearch(748, 176, 761, 266, 0xFFFF00, 0, 1, $Hwnd) $f = IsArray($ps) If Not $f Then $tc = PixelGetColor(1013, 260, $Hwnd) If IsColorMatch($tc, 0x404346, 40) Then ExitLoop MouseClick("left", 748, 176, 1, 5) Sleep(500) Send("{DOWN 5}") ; assume 5 items are in view Sleep(500) EndIf Until $f If $f Then MouseClick("left", $ps[0], $ps[1], 1, 5) Sleep(500) MouseClick("left", 793, 77, 1, 5) Sleep(3000) While IsSomeFunc() Sleep(3000) WEnd MouseClick("left", 825, 77, 1, 5) Sleep(20000) EndIf WEnd MsgBox(64, "Some Title", "OK") EndFunc Link to comment Share on other sites More sharing options...
martin Posted August 16, 2009 Share Posted August 16, 2009 The problem was the outer loop, not the inner one. There should not have been a difference between = and == in a boolean statement with autoit;Does that mean you didn't read my post or that you don't believe what I said? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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