Jump to content

Help with recursion problem


sumsar
 Share

Recommended Posts

Ok, I just started coding a short time ago, and I have run into a problem.

What I want it to do, is: As soon as a specific color appears, search for a second color and click the mouse wherever that color is found. And repeat.

When I run this script, it runs for awhile but then it stops because of: "Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.:"

Func skipper()
    $coord = PixelSearch(606, 504, 999, 621, 0x960000, 50)
If @error Then
    send("{F4}")
EndIf

If Not @error Then
    $coord = PixelSearch(606, 504, 999, 621, 0x6CB252)
    MouseClick ("left",$coord[0], $coord[1],1,0)
    send("{F4}")
EndIf
EndFunc

The hotkey for this func is F4

I have done some research and I know it's because the function is calling itself. And that a way to fix this is to make a loop, but I'm not sure how to do that.

So, yea. If someone could help me make this work. It would be greatly appreciated :)

Link to comment
Share on other sites

I'm willing to help on this because I need a bit of practice using a specification...

But I need some more information.

Is there a real need for this to be a function?

Will the script be used with another program? (Is this a bot?)

Why did you choose F4 to be the hotkey when you are using it in the script?

Still learning...I love autoit. :)

Link to comment
Share on other sites

Global $Working=False
HotKeySet("{F4}","skipper")
While 1
    Sleep(100)
Wend
Func skipper()
    $Working = Not $Working
    While $Working
        $coord = PixelSearch(606, 504, 999, 621, 0x960000, 50)
        If Not @error Then
            $coord = PixelSearch(606, 504, 999, 621, 0x6CB252)
            MouseClick ("left",$coord[0], $coord[1],1,0)
        EndIf
        Sleep(10)
    Wend
EndFunc

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

; Hotkey setup.
HotKeySet("^{F4}","_Skipper") ; CTRL + F4 is the new hotkey.
HotKeySet("{ESC}","_Term")    ; Press escape for exit hotkey.

; Loop until user exits.
While 1
    Sleep(100)
WEnd



Func _Skipper()
    $Time  = InputBox("","Enter the time to loop in seconds",60)*1000   ;The user inputs the seconds which is converted into milliseconds.
    $Timer = TimerInit()                                                ;Initialize a timer.
    Do                                                                                                  ;Another type of loop.
        $coord = PixelSearch(606, 504, 999, 621, 0x960000, 50)            ;Search for the first color. 
        If @error Then                                                                          ;If not found...
            Send("{F4}")                                                ; Press F4.
        Else                                                            ; Otherwise...
            $coord = PixelSearch(606, 504, 999, 621, 0x6CB252)              ; Search for the second color. 
            If @error then                                                                               ; If second color not found... 
                ;???                                                    ;  Nothing requested here
            Else                                                        ; Otherwise...
                MouseClick("left",$coord[0], $coord[1],1,0)                      ;  Click on it.
                Send("{F4}")                                            ;  Press F4.
            EndIf                                                                    ; Endif.
        EndIf                                                                         ;Endif.
        ;TrayTip("",TimerDiff($Timer)& "/" & $Time,0)                       ;Display: [Time passed / End time] In tray.
    Until TimerDiff($Timer) >= $Time                                            ;Go back to 'Do' if the time has not reached the requirement.
    ;TrayTip("","Loop ended.",0)                                        ;Inform user that the loop has finished.
EndFunc

Func _Term()
    Exit                                                                ;Exit script.
EndFunc

Couldnt find a way to edit... but didnt want to just delete this. Now you can choose between two.

Still learning...I love autoit. :)

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