wolfsnow11 Posted August 16, 2017 Share Posted August 16, 2017 sometimes my script will stop and gives me recursion error.. i have no idea why expandcollapse popupHotKeySet("+z", "Start") HotKeySet ("+x", "_Exit") Opt("MouseCoordMode", 2) Opt("PixelCoordMode", 2) While 1 ToolTip("press SHIFT Z TO START, SHIFT X TO EXIT", 1171, 781,"info",1,1) Sleep(1000) WEnd Func Start() send ("{enter}") sleep (2000) Mouseclick("primary", 541, 160, 10,5) sleep (200) call ("checkcolor") EndFunc func checkcolor) while 1 if pixelgetcolor (522, 466) <> 0xFFFFFF and pixelgetcolor(152,31) = 0xFFFFFF then send("{esc}") sleep (1000) else if pixelgetcolor (522, 466) = 0xFFFFFF and pixelgetcolor(152,31) = 0xFFFFFF then Mouseclick("primary", 404, 408, 10,5) sleep (8000) send ("{enter}") sleep (6000) ToolTip("Paused for 4mins to start again", 0, 0) sleep(240000) call ("start") Else call ("checkcolor") endif EndIf wend endfunc Func _Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2017 Moderators Share Posted August 16, 2017 wolfsnow11, Welcome to the AutoIt forums. You are repeatedly calling the checkcolor function from within the function itself - this is called recursion and usually leads to tears at bedtime. You might find the Recursion tutorial in the Wiki useful reading. M23 P.S And looking at your code, you might want to read the Forum rules as well! 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...
wolfsnow11 Posted August 16, 2017 Author Share Posted August 16, 2017 thank you. is there workaround to call checkcolor function within the loop without recursion? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2017 Moderators Share Posted August 16, 2017 wolfsnow11, You do not need a "workaround" - you need to recast your code so that you do not call functions from within themselves. 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...
wolfsnow11 Posted August 16, 2017 Author Share Posted August 16, 2017 func checkcolor) while 1 if pixelgetcolor (522, 466) <> 0xFFFFFF and pixelgetcolor(152,31) = 0xFFFFFF then send("{esc}") sleep (1000) else if pixelgetcolor (522, 466) = 0xFFFFFF and pixelgetcolor(152,31) = 0xFFFFFF then Mouseclick("primary", 404, 408, 10,5) sleep (8000) send ("{enter}") sleep (6000) ToolTip("Paused for 4mins to start again", 0, 0) sleep(240000) call ("start") Else call ("checkcolor2") endfunc func checkcolor2() call ("checkcolor") endfunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 16, 2017 Moderators Share Posted August 16, 2017 wolfsnow11, No, that will suffer the same problem because you are still calling functions from within themselves - you need to let functions finish first. With all the recursive calls the internal logic of the script is a bit confusing, so what exactly are you trying to do when you run it? If I can understand that, then I can see how the script might be structured to avoid recursion problems. 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...
Moderators Melba23 Posted August 16, 2017 Moderators Share Posted August 16, 2017 wolfsnow11, I think this might be what you are looking for: expandcollapse popupHotKeySet("+z", "Start") HotKeySet("+x", "_Exit") Opt("MouseCoordMode", 2) Opt("PixelCoordMode", 2) ; Set a timestamp for the tooltip Global $nTip_Time = TimerInit() ; Create a timestamp to check for the pause between runs Global $nStart_Time While 1 ; If more than 1 sec has elapsed If TimerDiff($nTip_Time) > 1000 Then ; Fire tooltip ToolTip("press SHIFT Z TO START, SHIFT X TO EXIT", 1171, 781, "info", 1, 1) ; Reset timestamp $nTip_Time = TimerInit() EndIf ; But still sleep a while to keep the CPU cool Sleep(10) WEnd Func Start() ConsoleWrite("Start code running" & @CRLF) ; Run the colour check code checkcolor() ; No need to use Call - just use the function name ; Wait until the timer has run for 4 mins Do Sleep(10) Until TimerDiff($nStart_Time) > 240000 ; And now run the code again EndFunc ;==>Start Func checkcolor() While 1 If PixelGetColor(522, 466) <> 0xFFFFFF And PixelGetColor(152, 31) = 0xFFFFFF Then Send("{esc}") Sleep(1000) ; We stay in the loop until the condition is not true Else ; Now we do a second check If PixelGetColor(522, 466) = 0xFFFFFF And PixelGetColor(152, 31) = 0xFFFFFF Then MouseClick("primary", 404, 408, 10, 5) Sleep(8000) Send("{enter}") Sleep(6000) ToolTip("Paused for 4mins to start again", 0, 0) ; Set timestamp for the next run $nStart_Time = TimerInit() ; Go back to the Start function which called this one Return EndIf ; If the check is not true then say in this function and run the loop again EndIf WEnd EndFunc ;==>checkcolor Func _Exit() Exit EndFunc ;==>_Exit 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...
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