Chaotica Posted December 19, 2008 Share Posted December 19, 2008 I have searched everywhere and read a lot of things about recursion, but I still cant figure out why my script errors. If somebody would kindly look over it and see anything, and give me pointers I would much appreciate it. It's a bot for a game.. its simple and it works perfectly for about 2 hours. remember its my first script. expandcollapse popupWhile 1=1 target() WEnd Func target() while 1=1 WinActivate("Game") send("hhh") MouseClick("left",880,220,2,1) sleep(200) MouseClick("left",190,300,2,1) sleep(200) MouseClick("left",220,260,2,1) sleep(200) MouseClick("left",330,265,2,1) sleep(200) MouseClick("left",350,230,2,1) If PixelSearch(720,120,730,130,0xFDFDFD,1) = @error = 0 Then attack() ExitLoop EndIf WEnd EndFunc Func attack() Send("222111") If PixelSearch(720,120,730,130,0xFEFEFE,5) = @error = 0 Then health() EndIf buffcheck() EndFunc Func buffcheck() sleep(200) If PixelSearch(775,765,825,785,0xDDDEC4,1) = @error = 0 Then rest() EndIf buff() EndFunc Func health() If PixelSearch(587,777,603,780,0x363722,5) = @error = 0 Then heal() EndIf attack() EndFunc Func heal() send("999") sleep(200) attack() EndFunc Func buff() Send("===") sleep(4500) Send("---") Sleep(800) send("000") rest() EndFunc Func rest() sleep(4800) If PixelSearch(692,779,710,780,0x363722,1) = @error = 0 Then sit() EndIf target() EndFunc Func sit() sleep(200) send("{x down}") sleep(100) send("{x up}") sleep(200) stand() EndFunc Func stand() while 1=1 sleep(300) If PixelSearch(692,779,693,780,0x363722,5) = @error = 1 Then target() ExitLoop EndIf WEnd EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 19, 2008 Share Posted December 19, 2008 I have searched everywhere and read a lot of things about recursion, but I still cant figure out why my script errors. If somebody would kindly look over it and see anything, and give me pointers I would much appreciate it. It's a bot for a game.. its simple and it works perfectly for about 2 hours. remember its my first script. expandcollapse popupWhile 1=1 target() WEnd Func target() while 1=1 WinActivate("Game") send("hhh") MouseClick("left",880,220,2,1) sleep(200) MouseClick("left",190,300,2,1) sleep(200) MouseClick("left",220,260,2,1) sleep(200) MouseClick("left",330,265,2,1) sleep(200) MouseClick("left",350,230,2,1) If PixelSearch(720,120,730,130,0xFDFDFD,1) = @error = 0 Then attack() ExitLoop EndIf WEnd EndFunc Func attack() Send("222111") If PixelSearch(720,120,730,130,0xFEFEFE,5) = @error = 0 Then health() EndIf buffcheck() EndFunc Func buffcheck() sleep(200) If PixelSearch(775,765,825,785,0xDDDEC4,1) = @error = 0 Then rest() EndIf buff() EndFunc Func health() If PixelSearch(587,777,603,780,0x363722,5) = @error = 0 Then heal() EndIf attack() EndFunc Func heal() send("999") sleep(200) attack() EndFunc Func buff() Send("===") sleep(4500) Send("---") Sleep(800) send("000") rest() EndFunc Func rest() sleep(4800) If PixelSearch(692,779,710,780,0x363722,1) = @error = 0 Then sit() EndIf target() EndFunc Func sit() sleep(200) send("{x down}") sleep(100) send("{x up}") sleep(200) stand() EndFunc Func stand() while 1=1 sleep(300) If PixelSearch(692,779,693,780,0x363722,5) = @error = 1 Then target() ExitLoop EndIf WEnd EndFunc I don't usually bother with gaming scripts, but this is a great first post, with code and everything, so you won me over. Although it might work in a perverse, accidental kind of way, this is wrong: If PixelSearch(720,120,730,130,0xFDFDFD,1) = @error = 0 Then attack() ExitLoop EndIf PixelSearch() returns an array. If you try to treat the entire array variable as an integer, is will always evaluate as 0, no matter what is actually inside the array. Order of operations will group them left to right, so you get the equivalent of: If (0 = @error) = 0 Then attack() ExitLoop EndIf Testing the @error out of a function on the same line you called the function might just be possible, but it's not a good idea (at least in AutoIt, perhaps it makes more sense in other languages). So do those tests like this: PixelSearch(720,120,730,130,0xFDFDFD,1) If @error = 0 Then attack() ExitLoop EndIf (Or, If @error = 1, as required.) You have a lot of recursion in this. For example, attack() calls health(), which in turn calls attack() again. That needs a rethink. Good luck with it, and Welcome to AutoIt. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Chaotica Posted December 19, 2008 Author Share Posted December 19, 2008 thanks a lot for your help, you gave me a few ideas I'll see what I can do Link to comment Share on other sites More sharing options...
Chaotica Posted December 20, 2008 Author Share Posted December 20, 2008 (edited) Cool I figured it out, It ran all last night with no errors so I think its all good to go. I even slimmed it down a lot. expandcollapse popupWhile 1=1 target() WEnd Func target() While 1=1 WinActivate("Game") MouseClick("left",880,220,2,1) sleep(200) MouseClick("left",190,300,2,1) sleep(200) MouseClick("left",220,260,2,1) sleep(200) MouseClick("left",330,265,2,1) sleep(200) MouseClick("left",350,230,2,1) PixelSearch(720,120,730,130,0xFDFDFD,1) If @error = 0 Then exitloop Else Return EndIf WEnd attack() EndFunc Func attack() while 1=1 sleep(200) Send("222111") PixelSearch(580,780,590,785,0x363722,1) If @error = 0 Then send("999") Else PixelSearch(720,120,730,130,0xFDFDFD,1) If @error = 1 Then ExitLoop EndIf EndIf WEnd buffcheck() EndFunc Func buffcheck() While 1=1 sleep(200) PixelSearch(775,765,825,785,0xDDDEC4,1) If @error = 0 Then ExitLoop Else sleep(200) Send("===") sleep(4500) Send("---") Sleep(800) send("000") sleep(200) ExitLoop EndIf WEnd rest() EndFunc Func rest() While 1=1 sleep(4800) PixelSearch(692,779,710,780,0x363722,1) If @error = 0 Then sleep(200) send("{x down}") sleep(100) send("{x up}") sleep(200) ExitLoop Else Return EndIf WEnd stand() EndFunc Func stand() while 1=1 sleep(300) PixelSearch(690,780,695,785,0x363722,1) If @error = 0 Then sleep(200) Else Return EndIf WEnd EndFunc Edited December 20, 2008 by Chaotica Link to comment Share on other sites More sharing options...
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