Jump to content

another recursion topic


Recommended Posts

Ok, I have read lots of the forums on how you cannot call a function from inside another fuction. But I simply do not understand how to get around this with my code. Any help would be appreciated.

$checkcount = 0
HotKeySet ("{ESC}", "MyExit")

sleep(5000)
Run(@AutoItExe & ' "' & @ScriptDir & '\healthloop.au3"')

bot()

Func bot()
    $coord =PixelSearch(0,78,750,390,14813666,10)
    If Not @error Then
     MouseClick ("left", $coord[0], $coord[1])
     check()
    else
     send("{RIGHT down}")
     sleep(2000)
     send("{RIGHT up}")
     bot()
    endif
EndFunc
    

Func behead()
    $coord2 =PixelSearch(327,259,520,417,14813666,10)
    If Not @error Then
     MouseClick ("right", $coord2[0], $coord2[1])
    endif
EndFunc

Func vitalbot()
    $coord3 =PixelSearch(260,220,567,439,14813666,10)
    If Not @error Then
     MouseClick ("left", $coord3[0], $coord3[1])
     check()
    else
     bot()
    endif
EndFunc
Func check()
    If $checkcount = 30 Then
        $checkcount = 0
        vitalbot()
    endif
    If PixelGetColor(342,47) <> 11145506 Then
        $checkcount = 0
        sleep(1000)
        send("6")
        sleep(1000)
        send("6")
        vitalbot()
    else
        sleep(1000)
        $checkcount = $checkcount + 1
        check()
    endif
EndFunc


Func MyExit ()
Exit
EndFunc
Link to comment
Share on other sites

  • Developers

You need to use Return to return to the Calling function.

e.g. this portion:

bot()

Func bot()
    $coord =PixelSearch(0,78,750,390,14813666,10)
    If Not @error Then
        MouseClick ("left", $coord[0], $coord[1])
     check()
    else
     send("{RIGHT down}")
     sleep(2000)
     send("{RIGHT up}")
     bot()
    endif
EndFunc

Probably needs to look like:

While 1  
    bot()
Wend
Func bot()
    $coord =PixelSearch(0,78,750,390,14813666,10)
    If Not @error Then
        MouseClick ("left", $coord[0], $coord[1])
     check()
    else
     send("{RIGHT down}")
     sleep(2000)
     send("{RIGHT up}")
     return
    endif
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Welcome to the forums!

I'm not entirely sure about what you mean by this remark:

I have read lots of the forums on how you cannot call a function from inside another fuction.

because you do call other functions from within functions, so perhaps you mean that you can't recursively call the same function.

You can in fact do this -- here's a link to a piece of code that does just this. I hope it clears up some confusion!

Edit: Obviously recursive functions require some form of terminating condition -- otherwise they'll continue to call themselves until there's no memory left. Your code looks like it might be doing that so you'll want to take a look at some loop constructs like Do..Until or While..WEnd -- JdeB has mentioned this anyway.

Also note that if a function reaches its end (i.e. the EndFunc instruction) then at that point the script control will return to where the function was initially called -- calling a function isn't like a traditional GoTo.

Sorry if I'm long off-track! :">

Edited by LxP
Link to comment
Share on other sites

thanks for your help.. but i have one more question.. where does return go to when it executes? does it go back to the begging of the function or back to the begging of the script? thanks.

as stated above by LxP

..... then at that point the script control will return to where the function was initially called --

8)

NEWHeader1.png

Link to comment
Share on other sites

is there a way to make it return to the begginning of a function? then go to another function once its done.. for instance check the "check()" function in my code posted above.. I want it to check() again if the pixel color is not a certain color? how can i do this? .. i dont think a simple while statement will work because I want it to stop after the color of the pixel is not a certain color. I hope this isnt too confusing to understand. >.<

Edited by rejectpenguin
Link to comment
Share on other sites

maybe like this

Dim $checkcount = 0, $bot = 1, $check = 0, $vital = 0
HotKeySet ("{ESC}", "MyExit")

sleep(5000)
Run(@AutoItExe & ' "' & @ScriptDir & '\healthloop.au3"')

While 1
    If $bot = 1 Then
        bot()
        $bot = 0
    EndIf
    If $check = 1 Then
        check()
        $check = 0
    EndIf
    If $vital = 1 Then
        vitalbot()
        $vital = 0
    EndIf
Sleep(20)
WEnd
Func bot()
    $coord =PixelSearch(0,78,750,390,14813666,10)
    If Not @error Then
        MouseClick ("left", $coord[0], $coord[1])
     $check = 1
     Return
    else
     send("{RIGHT down}")
     sleep(2000)
     send("{RIGHT up}")
     $bot = 1
    endif
EndFunc
    

Func behead()
    $coord2 =PixelSearch(327,259,520,417,14813666,10)
    If Not @error Then
        MouseClick ("right", $coord2[0], $coord2[1])
    endif
EndFunc

Func vitalbot()
    $coord3 =PixelSearch(260,220,567,439,14813666,10)
    If Not @error Then
        MouseClick ("left", $coord3[0], $coord3[1])
        $check = 1
        Return
    else
        $bot = 1
    endif
EndFunc
Func check()
    If $checkcount = 30 Then
        $checkcount = 0
        $vital = 1
        Return
    endif
    If PixelGetColor(342,47) <> 11145506 Then
        $checkcount = 0
        sleep(1000)
        send("6")
        sleep(1000)
        send("6")
        $vital = 1
        Return
    else
        sleep(1000)
        $checkcount = $checkcount + 1
        $check = 1
    endif
EndFunc


Func MyExit ()
Exit
EndFunc

8)

Edited by Valuater

NEWHeader1.png

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