Jump to content

recursion


Recommended Posts

Hey guys,

I'm back again with another problem. I've got my program working almost exactly as I want it to, but after it runs for a while (+-30 min or so), I get that popular recursive error when the stack fills up and AutoIt bails before bringing down my whole rig.

Anyway, I've searched around and it seems that the answer to this problem is to work the code in such a way that your functions all get the chance to terminate. Unfortunately, in my situation, it is especially convenient for functions to just sort of chain together without ever really terminating, ie:

Func_one()
 stuff
 func_two()
endfunc

Func_two()
 stuff
 if condition = true
 func_three()
 else
 func_four()
endfunc

etc..

So, my question is this: is there any way that I can manually kill those functions with a command? Really, I can't figure out how to preserve all the functionality of my program without having it set up in the way that I do, but it also needs to be able to run for more than half an hour at a time.

And yes, I've searched.

Any advice is much appreciated.

Thanks,

Stinga

Link to comment
Share on other sites

Aw... you want loop that, but avoid these functions?

While 1
;for example
If MsgBox(4,"Continue","Do you want continue script? (Exit from loop)") = 6 Then ExitLoop
Wend
MsgBox(0,"End","Loop end, script end!")
;not tested

Tell me if I don't understand you fully.

i542

EDIT: Oh, stupid I, never don't preview post...

Edited by i542

I can do signature me.

Link to comment
Share on other sites

As Randall stated, there's not enough code there to give a detailed response. In any case, you are going to need to structure your script to allow each function to return. This is not difficult and there are many methods available. One method I use most often is I have a variable, usually $V in my case, which I assign a value depending on the conditions met within each function. Example:

Global $V = 1

While (1)
 Select
  Case $V = 1
   Function1 ()
  Case $V = 2
   Function2 ()
  Case $V = 3
   Function3 ()
  Case $V = 4
   Exit
 EndSelect
WEnd

Func Function1 ()
 
 If condition = true Then
  $V = 2
 Else
  $V = 3
 EndIf
 
 Return
 
EndFunc

Func Function2 ()
 
 If condition = true Then
  $V = 1
 Else
  $V = 3
 EndIf
 
 Return
 
EndFunc

Func Function3 ()
 
 If condition = true Then
  $V = 4
 Else
  $V = 1
 EndIf
 
 Return
 
EndFunc

Nomad :D

edit: hmm, my autoit tags aren't working

Edited by Nomad
Link to comment
Share on other sites

This is great, guys. Thanks a ton for the help. It looks like I'm just going to have to get creative and do some reorganizing on my code.

Thanks for the sample bits! I'm sure I'll be back in in another couple weeks with a new issue!

-Stinga

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