Jump to content

Recursion leve has been exceeded


Guest abcba
 Share

Recommended Posts

Hello, I'm pretty new to this and by all means I'm not very good at programming or coding so I was wondering if anyone can help me with my script:

-----

Sleep(3000)

check()

func check()

If PixelGetColor(1,2) = 0000000 then

Sleep(200)

Send("{Enter}");

check2()

endif

If PixelGetColor(1,2) = 11111111 then

check2()

endif

endfunc

func check2()

Sleep(200)

check()

endfunc

-----

This can only run for about 46 seconds then I get an error saying recursion level has been exceeded and will quit to prevent stack overflow. What I'm trying to do is pretty simple, just when a pixel is a certain color, a key is pressed and if that pixel isn't that color, it does nothing. I want this to loop infinitely, but with this script, it seems I can't. Can anyone help me out? I will give you a cookie.

Edited by abcba
Link to comment
Share on other sites

Maybe you meant:

Sleep(3000)
check()

Func check()
   If PixelGetColor(1, 2) = 0000000 Then
      Sleep(200)
      Send("{Enter}");
      Sleep200()
   EndIf
   If PixelGetColor(1, 2) = 11111111 Then
      Sleep200()
   EndIf
EndFunc  ;==>check

Func Sleep200()
   Sleep(200)
EndFunc  ;==>Sleep200

... and it seems you ignore that funcs returns (via return command or EndFunc) to the point you called them.

Link to comment
Share on other sites

I don't understand. Doesn't that just make it run once? Is there something to run a function over and over again? I tried what you have there but it seems to stop after one run. Thank you for the quick reply.

Link to comment
Share on other sites

The point is that the first func calls the second that again calls the first. As you should understand this bring to a continuos recall that block the script.

To repeat again and again you have to use the looping functions: While, Do or For.

For a simple unlimited repeating you should do:

Sleep(3000)
While 1;While 1 is 1 (always) do
   check() ;my check Func
Wend;and return to While tag

Exit
Func check()
  If PixelGetColor(1, 2) = 0000000 Then
     Sleep(200)
     Send("{Enter}");
     Sleep200()
  EndIf
  If PixelGetColor(1, 2) = 11111111 Then
     Sleep200()
  EndIf
EndFunc ;==>check

Func Sleep200()
  Sleep(200)
EndFunc ;==>Sleep200

Do you see?

The Func are somewhat new commands. And a couple of new commands should not call each other.

Link to comment
Share on other sites

Basically think of it this way, you want to complete the functions.

To loop, set up a loop. While...wend for..next do..until. These will repeat when they hit thier end tag.

your func never hits it's endfunc. so that function is still running, and then you open one more than never ends, and so on and so on.

good:

while 1
go()
wend; after completing go() this completes and starts again at while 

func go()
sleep(1)
endfunc; when complete this returns

bad:

check()

func check()
go(); jumps to go
endfunc; this never completes, so BAD!

func go()
sleep(1)
check(); jumps to check
endfunc; this never completes, so BAD!

the first example, everything completes and is happy, the second although looks good, never completes and if each start func takes up a tiny bit of memory, you will eventually lock up the system, so there are checks in place to stop that.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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