wolfsnow11

Recursion level has been exceeded

7 posts in this topic

#1 ·  Posted

sometimes my script will stop and gives me recursion error.. i have no idea why

 

HotKeySet("+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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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._______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

#3 ·  Posted

thank you. is there workaround to call checkcolor function within the loop without recursion?

Share this post


Link to post
Share on other sites

#4 ·  Posted

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._______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

#5 ·  Posted

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

Share this post


Link to post
Share on other sites

#6 ·  Posted

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._______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

#7 ·  Posted

wolfsnow11,

I think this might be what you are looking for:

HotKeySet("+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._______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