Jump to content

Error: Recursion


Recommended Posts

Error: Recursion level has been exceeded - Autoit will quit to prevent stack overflow.

Thats the error. I actually want my things to loop over and over. I had it going without any sleeps and that happened. Right now I've tested it but it's not error'd out yet. I assume it will at some point, but because of the sleeps it's going to take it alot longer. Is there anyway to fix this issue while running the same checks over and over.

Here is my code.

Func CntrlQ()
    ToolTip('Warping to Station"',0,0)
    Sleep ( 500 )
EndFunc

Global $Shield = 0
Func ShieldCheck(); Checks Shields to see if their in Danger Level
    ToolTip('Checking Shields"',0,20)
    PixelSearch ( 446, 685, 446, 685, 0xBCBCBC, 10 )
    If @error Then
        ToolTip('Shields cntrlq"',0,0)
        Sleep ( 250 )
        Call ( "CntrlQ" )
    EndIf
    Sleep ( 500 )
    Call ( "LocalCheck" )
EndFunc

; +37 pixel to each spot
; Spot1 278, 239
; Spot2 278, 276
; Spot3 278, 313
; Spot4 278, 350
; Spot5 278, 387
; Spot6 278, 424
; Spot7 278, 461
; Spot8 278, 498
; Spot9 278, 535
; Spot10 278, 572
; Spot11 278, 609
; Spot12 278, 646
; Spot13 278, 683
; Spot14 278, 720
; Neut Color #878989
; At War Color #980A0A
; Bad Standins #C14603

Global $LocalCheck = 0
Global $HostileColor[3][1] = [[0x878989],[0x980A0A],[0xC14603]]
Global $HSpot[14][2] = [[278, 239],[278, 276],[278, 313],[278, 350],[278, 387],[278, 424],[278, 461],[278, 498], _
                     [278, 535],[278, 572],[278, 609],[278, 646],[278, 683],[278, 720]]

Func LocalCheck(); Check Local for Hostiles
    ToolTip('Checking Local"',0,30)
    For $y = 0 to 2
        For $x = 0 to 13
            $coord = PixelSearch($HSpot[$x][0], $HSpot[$x][1], $HSpot[$x][0], $HSpot[$x][1], $HostileColor[$y][0], 20 )
            If Not @error Then
                ToolTip('Hostile cntrlq"',0,0)
                Sleep ( 250 )
                Call ( "CntrlQ" )
            EndIf
        Next
    Next
    Sleep ( 500 )
    Call ( "ShieldCheck" )
EndFunc

; Local calls ShieldCheck and ShieldCheck calls Local to Loop checks
Call ( "LocalCheck" )

Basically Local calls shield, shield calls local. So is there a way to not get this recursion error? Or will I not get it because of the sleep commands I've added in so it's slower now?

Link to comment
Share on other sites

I'm not that familiar with how AutoIt handles recursion, but if you're recursively calling scripts from within each other with no limits you'll run into resource issues at some point regardless of a built in recursion limit in AutoIt.

I'd hazard a guess that when a function calls another function it doesn't end the first function instance, so you're going to end up with umpteen million instances of each function trying to process.

I think preferably you want it to:

Call LocalCheck

End LocalCheck

Call ShieldCheck

End ShieldCheck

and loop that

Whereas if I'm reading it right at the moment you're doing:

Call LocalCheck

Call ShieldCheck

Call LocalCheck

Call ShieldCheck

etc

without ever terminating any of the function instances.

Link to comment
Share on other sites

Link to comment
Share on other sites

I actually figured out a way to do it very easily with a Do Until. Is there any reason I would want to use a While WEnd over a Do Until?

Global $Loop = 0
Func LocalLoop()
    Do
        Call ( "LocalCheck" )
        Call ( "ShieldCheck" )
    Until $Loop = 1
EndFunc
Link to comment
Share on other sites

I actually figured out a way to do it very easily with a Do Until. Is there any reason I would want to use a While WEnd over a Do Until?

Global $Loop = 0
Func LocalLoop()
    Do
        Call ( "LocalCheck" )
        Call ( "ShieldCheck" )
    Until $Loop = 1
EndFunc
forgetoo, DO NOT use the Call() function, where it is not required. Edited by Yashied
Link to comment
Share on other sites

As far as I'm aware the only real difference between a While and a Do loop is the While loop tests the condition BEFORE each loop starts, whereas Do tests the condition AFTER. For your case, I can't see that mattering as the condition is never in an end state anyway.

But, why still using Call()?

Edited by Khab
Link to comment
Share on other sites

As far as I'm aware the only real difference between a While and a Do loop is the While loop tests the condition BEFORE each loop starts, whereas Do tests the condition AFTER.

You're right, this is a much easier way to call the functions in a loop

while 1
    LocalCheck()
    ShieldCheck()
wend
Link to comment
Share on other sites

Recursion is something like that:

MsgBox(0, "Recursion", Fibonacci_r(10))
Func Fibonacci_r($f)
    If $f = 0 Then Return 0
    If $f = 1 Then Return 1
    Return Fibonacci_r($f - 1) + Fibonacci_r($f - 2)
EndFunc

Recursion is slower than the iterative method!

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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