Slvrngrn Posted September 24, 2009 Posted September 24, 2009 (edited) I have a bot I've written but I occasionally get a stack overflow. I am curious as to whether this function could be the culprit. Basically this function clicks on the screen at the character's feet, then "looks" to see if a pop-up has opened or not. If the pop-up is not there then it waits ten seconds and tries again. (If it's important, this is because at times other characters or mobs can get in your way preventing rest of the script from functioning properly because the pop-up is missing.) My concern is that I have a Func referring to itself. Is this bad? If so, is there another way to accomplish the same result? Thanks everyone. This is my first post on AutoIt forums, so if I committed some sort of etiquette breech just tell me and I'll fix it. Please don't flame me. Func FeetOnFarm() BlockInput(1) Sleep(375) MouseClick("left", 505, 391, 1, 1); feet Sleep(375) BlockInput(0) $FOF = PixelSearch(268, 268, 273, 273, 0xFFFBFF, 3) If @error Then Sleep(10000) FeetOnFarm() EndIf EndFunc Edited September 24, 2009 by Slvrngrn
cageman Posted September 24, 2009 Posted September 24, 2009 (edited) Func FeetOnFarm() Do BlockInput(1) Sleep(375) MouseClick("left", 505, 391, 1, 1); feet Sleep(375) BlockInput(0) $FOF = PixelSearch(268, 268, 273, 273, 0xFFFBFF, 3) If @error Then Sleep(10000) EndIf Until NOT @error EndFunc that should work better? this would repeat the function until no error. You could also do IsArray($FOF) to check if it found a colour. then te last part should be: If NOT IsArray($FOF) Then sleep(10000) Endif Until IsArray($FOF) edit: oh and to your question if its a bad thing. yes it is. your function is called a recursion and will call itself multiple times. this is hard for a computer. Edited September 24, 2009 by cageman
Bowmore Posted September 24, 2009 Posted September 24, 2009 (edited) @cagemanYour first version loop will not work as expected as Sleep(10000) will reset @error to 0Try ThisFunc FeetOnFarm() Local $bTryAgain = False Local $FOF = 0 Do $bTryAgain = False BlockInput(1) Sleep(375) MouseClick("left", 505, 391, 1, 1); feet Sleep(375) BlockInput(0) $FOF = PixelSearch(268, 268, 273, 273, 0xFFFBFF, 3) If @error Then Sleep(10000) $bTryAgain = True EndIf While $bTryAgain Return $FOF EndFunc Edited September 24, 2009 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
monoceres Posted September 24, 2009 Posted September 24, 2009 Recursion is fine. As long as you do it right! Infinity recursion == Fail. Also, it should not be used like this, it should be used on specific problems. Broken link? PM me and I'll send you the file!
Slvrngrn Posted September 24, 2009 Author Posted September 24, 2009 (edited) Thanks cageman and everyone else! Great responses and lots of help. It's always a good day when you learn something new. I didn't even consider stacking commands inside a Do/While loop. I really appreciate the help! Edited September 24, 2009 by Slvrngrn
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now