Jump to content

Error: Recursion level exceeded


Calcii
 Share

Recommended Posts

Hi, dear developers!

At first i wanna speak to big thanks for that program, very effective for different tasks

Help me to solve that problem with Recursion error.

Error appear after the some time(about 3 hours) on line 52 "sleep(112000)"

Here my code:

Opt ("SendKeyDelay", 1       )
Opt ("WinTitleMatchMode", 4  )
Opt ("SendKeyDownDelay", 60  )
Opt ("MouseClickDownDelay", 20)

HotKeySet ("{F6}",  "TestDisc")
HotKeySet ("{F10}", "Stop")

WinActivate ("Classname=MU")
WinActivate ( "фФјЈґ°їзмФ [url=http://cesdn.net]http://cesdn.net[/url] №ьвўпб°Ф" ) 
WinMove ( "фФјЈґ°їзмФ [url=http://cesdn.net]http://cesdn.net[/url] №ьвўпб°Ф", "", 0, 0,)

;***************** Stop *****************
Func Stop ()
While 1 = 1
Sleep (1000)
Wend
EndFunc
;*************** repeater ***************
While (1)
Sleep (1)
WEnd
;****************  F6  *****************
Func TestDisc ()
if PixelGetColor(322,117) = 0xFFFFFF and PixelGetColor(480,119) = 0xFFFFFF Then
    MouseClick("left", 400, 160, 1)
    WinClose ("MU Update tool")
    call ("Connect")
Else
    call ("Cast")
Endif
Endfunc

Func Cast ()
While (1)

Send ("4")
MouseClick("Right", 730, 40, 1)
MouseClick("Right", 730, 40, 1)
MouseClick("Right", 40, 40, 1)
MouseClick("Right", 40, 40, 1)
MouseClick("Right", 730, 500, 1)
MouseClick("Right", 730, 500, 1)
MouseClick("Right", 40, 500, 1)
MouseClick("Right", 40, 500, 1)

Send ("1")
MouseMove (407, 256 ,1)
MouseDown ("Right")
Sleep (112000)
MouseUp ("Right")

call ("TestDisc")
WEnd
EndFunc

Func AgainPD ()
WinClose ("MU Update tool")
call ("Connect")
sleep (800)
EndFunc


Func Connect ()
    Run ( "c:\MU\MU.bat", "c:\MU\")
    WinActivate ("MU Update tool")
    Sleep (1000)
    MouseClick ("left", 712, 631, 1)
    WinActive ("фФјЈґ°їзмФ [url=http://cesdn.net]http://cesdn.net[/url] №ьвўпб°Ф")
    WinActive ("Classname=MU")
    Sleep (15000)
    Send ("{f12}")
    Sleep (2000)
    WinActive ("фФјЈґ°їзмФ [url=http://cesdn.net]http://cesdn.net[/url] №ьвўпб°Ф")
$server = PixelGetColor(411,314)
if $server = 0x272627 Then
    Sleep (2000)
    MouseClick ("left", 411,314, 1)
    sleep (1000)
    MouseClick ("left", 411,314, 1)
    sleep (4000)
    MouseClick ("left", 530,321, 1) ;1-server 550,280 2-server 530, 280 3-server
    sleep (4000)
Else
    Call ("AgainPD")
Endif
           
$pass = PixelGetColor(287,450)
if $pass = 0xFFEEDD Then
    Send ("login{TAB}pass{Enter}")
    sleep (5000)
Else 
    Sleep (7000)
    if $pass = 0xFFEEDD Then
        Send ("login{TAB}pass{Enter}")
        sleep (5000)
    Else 
        Call ("AgainPD")
    Endif
Endif   

$Char = PixelGetColor (753,322)
if $Char = 0x000000 Then
    MouseClick ("left", 220, 390, 2)  ;Char 1=220, 390 2=310, 390
    Sleep (5000)
Else
    Sleep (7000)
    if $Char = 0x000000 Then
        MouseClick ("left", 220, 390, 2)
        Sleep (5000)
    Else
        Call ("AgainPD")
    Endif
Endif

$Game = PixelGetColor (22, 514)
if $Game = 0x000000 Then
    Send ("{Enter}/re off{Enter}")
    call ("Cast")
Else
    Sleep (4000)
    if $Game = 0x000000 Then
        Send ("{Enter}/re off")
        call ("TestDisc")
    Else 
        Call ("AgainPD")
    Endif
Endif
Endfunc
Edited by Calcii
Link to comment
Share on other sites

TestDisc calls Cast which calls TestDisc in a recursive loop:

Func TestDisc ()
  if PixelGetColor(322,117) = 0xFFFFFF and PixelGetColor(480,119) = 0xFFFFFF Then
    MouseClick("left", 400, 160, 1)
    WinClose ("MU Update tool")
    call ("Connect")
  Else
    call ("Cast")
  Endif
Endfunc

Func Cast ()
  While (1)
    ...
    call ("TestDisc") <-- Recursion
  WEnd
EndFuncoÝ÷ Ø l£*.v÷öÙÞyÛhºÇ­àWîËb¢qh­ìZ^jëh×6Func TestDisc ()
  if PixelGetColor(322,117) = 0xFFFFFF and PixelGetColor(480,119) = 0xFFFFFF Then
    MouseClick("left", 400, 160, 1)
    WinClose ("MU Update tool")
    Connect()
  Else
    Cast()
  Endif
Endfunc
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

TestDisc calls Cast which calls TestDisc in a recursive loop:

Yes that loop, but i need unlimited number of repeat, until execute conditions

Also, you don't need to use the Call() function

Thx a lot, i will test without "call" and write results Edited by Calcii
Link to comment
Share on other sites

Yes that loop, but i need unlimited number of repeat, until execute conditions

Let's break this down into simple terms. You're creating an infinite loop. TestDesc() calls Cast() which calls TestDesc() again. That's recursion. Recursion is bad. Unless AutoIt stoped you, you'd consume all of the memory in your computer and it would crash.

Look up the "Return" statement in the AutoIt help and buy a good book on fundamental programming practices. Both will serve you well. :whistle:

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Let's break this down into simple terms. You're creating an infinite loop. TestDesc() calls Cast() which calls TestDesc() again. That's recursion. Recursion is bad. Unless AutoIt stoped you, you'd consume all of the memory in your computer and it would crash.

Look up the "Return" statement in the AutoIt help and buy a good book on fundamental programming practices. Both will serve you well. :whistle:

there's also a loop between againPD and connect

I call this type of coding "Moebius bandage" coding style

Hard to understand and the shortest way to bugs

Also apart from recursion to do an infinite loop in functions called with hotkeys may give strange result as when the hotkeys are pressed, the functions already running continue. In this program there are loops in almost every function either directly or via "Moebius bandage coding"

For example, the stop hotkey must be changed so that the program returns to the initial loop, with a global variable $runningMode

Opt ("SendKeyDelay", 1       )
Opt ("WinTitleMatchMode", 4  )
Opt ("SendKeyDownDelay", 60  )
Opt ("MouseClickDownDelay", 20)

HotKeySet ("{F6}",  "Start")
HotKeySet ("{F10}", "Stop")
HotKeySet ("{ESC}", "Exiting")

global $runningMode=1


while 1
    sleep(1)
    if $runningMode=1 then  TestDisc()
    if $runningMode=-1 then  Exit
wend

;****************
Func Start()
    $runningMode=1
endFunc

;****************
Func Stop()
    $runningMode=0
endFunc

;****************
Func Exiting()
    $runningMode=-1
endFunc

;****************
Func TestDisc()
...
EndFunc

And for the TestDisc, before coding write on a white paper what you want tot do with your disc. You must do what you want and then return. It's the $runningMode variable which monitor what kind of activity you have

Edited by tresa
Link to comment
Share on other sites

Please, show me example or way how i can do it without recursion?

tresa or PaulIA? Or any good peoples? :whistle:

How can i do it? Permanent test on disconnect Func TestDisc ()

It's example of program:

-----------------------------------

HotKeySet ("{F6}",  "Start")
;****************
global $runningMode=0

while 1
     sleep(1)
     if $runningMode=1      then  feex ()
     if $runningMode=-1     then  Exit
wend
;****************
Func Start()
     $runningMode=1
endFunc
;****************
Func Stop()
     $runningMode=0
endFunc
;****************
Func Exiting()
     $runningMode=-1
endFunc
;*********** 
Func feex ()
$Game = PixelGetColor (300, 600)
if $Game = 0x00FFFFFF Then
     MouseMove( 300, 600 )
     call ("feeex")
Else
     Exit
Endif
Endfunc
;****************************
Func feeex ()
$dot = PixelGetColor (100, 600)
if $dot = 0x00FFFFFF Then
     MouseMove( 100, 600 )
     call ("feex")
Endif

Endfunc
Edited by Calcii
Link to comment
Share on other sites

  • Moderators

Please, show me example or way how i can do it without recursion?

tresa or PaulIA? Or any good peoples? :whistle:

How can i do it? Permanent test on disconnect Func TestDisc ()

Recursion errors require a re-write on your part 99% of the time . What you're asking for "help" with, isn't help, it's asking someone to re-write your script for you so that it works. There have already been "examples" on how to do "your" script right above, just scrap what you have and take their advice from there. (at least it's a small script and not 10,000 lines of code you'd have to do it on)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Recursion errors require a re-write on your part 99% of the time . What you're asking for "help" with, isn't help, it's asking someone to re-write your script for you so that it works. There have already been "examples" on how to do "your" script right above, just scrap what you have and take their advice from there. (at least it's a small script and not 10,000 lines of code you'd have to do it on)

I don't know why recursion have appear, why program absorb all memory? Program remember all variables? Or what?
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...