Sign in to follow this  
Followers 0
Methos

Max recursion

5 posts in this topic

#1 ·  Posted (edited)

I got an error in a script i was writing saying i've reached the max recursion level. Is there a way to set this to infinite? This is supposed to be an endless loop.

Heres my script:

; shortcut/cmdline example: C:\idletest.exe "C:\example\example.exe" 18 10000

;getting the data from the command line
$resetrunprogram = $CmdLine[1];command to run when reset is called
$resetcycles = $CmdLine[2]; number of cycles before reset
$cycletime = $CmdLine[3]; cycle length in milliseconds

Dim $time1; is the initial value to compare against
Dim $time2; value sampled each idle cycle

$isidle = 0;0=not idle last check 1=idle last check
$idlecycle = 0; number of cycles(10 seconds) idle. 18=reset


First()

Func First()
    $time1 = MouseGetPos();get initial position of mouse
;MsgBox(0, "time1", $time1[0] & " and " & $time1[1], 2)
    Start()
EndFunc

Func Start()
    Sleep($cycletime)
    $time2 = MouseGetPos(); get second position of mouse
;MsgBox(0, "time2", $time2[0] & " and " & $time2[1], 2)
    Compare()
EndFunc

Func Compare()
    If $time1[0] <> $time2[0] OR $time1[1] <> $time2[1] Then
  $isidle = 0
  $idlecycle = 0
  $time1 = 0
  $time2 = 0
;MsgBox(0, "not idle", "We're not idle in Compare Stage 1", 2)
  First()

    ElseIf $time1[0] = $time2[0] AND $time1[1] = $time2[1] Then
  If $idlecycle >= $resetcycles Then
    $isidle = 1
  ;MsgBox(0, "idle, going to reset", "we're going to reset!", 2)
    Reset()
  Else
    $idlecycle = $idlecycle + 1
    $isidle = 1
    $time2 = 0
  ;MsgBox(0, "idle, ticking +1", "idle for " & $idlecycle & " cycles", 2)
    Start()
  EndIf
    EndIf
EndFunc

Func Reset()
;MsgBox(0, "Running the reset!", "woot, we're resetting because we've been idle 3 minutes")
    Run($resetrunprogram)
    $isidle = 0
    $idlecycle = 0
    $time1 = 0
    $time2 = 0
    First()
EndFunc

Thanks in advance!

Edited by Methos

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

I got an error in a script i was writing saying i've reached the max recursion level.  Is there a way to set this to infinite?  This is supposed to be an endless loop.

Heres my script:

Thanks in advance!

There is a difference between a indefinate loop and indefinate recursion.

None of your calls to Func's ever end ... they keep on calling each other.

Just let them end with a return code and act on that....

I hope this clearifies it a bit ...... :ph34r:

; shortcut/cmdline example: C:\idletest.exe "C:\example\example.exe" 18 10000

;getting the data from the command line
$RESETRUNPROGRAM = $CMDLINE[1];command to run when reset is called
$RESETCYCLES = $CMDLINE[2]; number of cycles before reset
$CYCLETIME = $CMDLINE[3]; cycle length in milliseconds

Dim $TIME1; is the initial value to compare against
Dim $TIME2; value sampled each idle cycle

$ISIDLE = 0;0=not idle last check 1=idle last check
$IDLECYCLE = 0; number of cycles(10 seconds) idle. 18=reset


First()

Func First()
   $TIME1 = MouseGetPos();get initial position of mouse
  ;MsgBox(0, "time1", $time1[0] & " and " & $time1[1], 2)
   Start()
EndFunc  ;==>First

Func Start()
   Sleep($CYCLETIME)
   $TIME2 = MouseGetPos(); get second position of mouse
  ;MsgBox(0, "time2", $time2[0] & " and " & $time2[1], 2)
   If Compare() then Return
   
EndFunc  ;==>Start

Func Compare()
   If $TIME1[0] <> $TIME2[0] Or $TIME1[1] <> $TIME2[1] Then
      $ISIDLE = 0
      $IDLECYCLE = 0
      $TIME1 = 0
      $TIME2 = 0
     ;MsgBox(0, "not idle", "We're not idle in Compare Stage 1", 2)
     ;First()
      return 1
      
   ElseIf $TIME1[0] = $TIME2[0] And $TIME1[1] = $TIME2[1] Then
      If $IDLECYCLE >= $RESETCYCLES Then
         $ISIDLE = 1
        ;MsgBox(0, "idle, going to reset", "we're going to reset!", 2)
         Reset()
         Return 1
      Else
         $IDLECYCLE = $IDLECYCLE + 1
         $ISIDLE = 1
         $TIME2 = 0
        ;MsgBox(0, "idle, ticking +1", "idle for " & $idlecycle & " cycles", 2)
         return 0
        ;Start()
      EndIf
   EndIf
EndFunc  ;==>Compare

Func Reset()
  ;MsgBox(0, "Running the reset!", "woot, we're resetting because we've been idle 3 minutes")
   Run($RESETRUNPROGRAM)
   $ISIDLE = 0
   $IDLECYCLE = 0
   $TIME1 = 0
   $TIME2 = 0
EndFunc  ;==>Reset
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yeah, that definately helps. Now lets see if I can put it all togeather right. :ph34r:

Thanks!

Share this post


Link to post
Share on other sites

Yeah, that definately helps.  Now lets see if I can put it all togeather right. :ph34r:

Thanks!

just modified my post ... it includes also the reset()... think this should do it...

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Cool, heres what im testing now.

;C:\idletest.exe "C:\windows\tutorial\blah.exe" 18 10000

;getting the data from the command line
$RESETRUNPROGRAM = $CmdLine[1]
$RESETCYCLES = $CmdLine[2]
$CYCLETIME = $CmdLine[3]

Dim $TIME1; is the initial value to compare against
Dim $TIME2; value sampled each idle cycle

$ISIDLE = 0;0=not idle last check 1=idle last check
$IDLECYCLE = 0; number of cycles(10 seconds) idle. 18=reset

While 1 = 1
    First()
Wend

Func First()
  $TIME1 = MouseGetPos();get initial position of mouse
  If Start() then Reset()
EndFunc ;==>First

Func Start()
  Sleep($CYCLETIME)
  $TIME2 = MouseGetPos(); get second position of mouse
  If Compare() then Return 1
EndFunc ;==>Start

Func Compare()
  If $TIME1[0] <> $TIME2[0] Or $TIME1[1] <> $TIME2[1] Then
     $ISIDLE = 0
     $IDLECYCLE = 0
     $TIME1 = 0
     $TIME2 = 0
     return 0
     
  ElseIf $TIME1[0] = $TIME2[0] And $TIME1[1] = $TIME2[1] Then
     If $IDLECYCLE >= $RESETCYCLES Then
        $ISIDLE = 1
    return 1
     Else
        $IDLECYCLE = $IDLECYCLE + 1
        $ISIDLE = 1
        $TIME2 = 0
        return 0
     EndIf
  EndIf
EndFunc ;==>Compare

Func Reset()
    Run($RESETRUNPROGRAM)
    $ISIDLE = 0
    $IDLECYCLE = 0
    $TIME1 = 0
    $TIME2 = 0
EndFunc

Thanks for the help again! :ph34r:

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
Sign in to follow this  
Followers 0