giorgio007 Posted July 31, 2014 Share Posted July 31, 2014 Hi! After half an hour usage, i get error message. What's the problem? Anyone could help me? What does it mean this line? expandcollapse popup#include-once ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance) return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) EndFunc Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance) $findImage = "*TRANSBLACK " & $findImage if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) if $result = "0" then return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0],"|") If(UBound($array) >= 4) Then $x = Int(Number($array[2])) $y = Int(Number($array[3])) if $resultPosition = 1 then $x = $x + Int(Number($array[4])/2) $y = $y + Int(Number($array[5])/2) endif return 1 EndIf EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for an image to appear ; ; Syntax: _WaitForImageSearch, _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance) $waitSecs = $waitSecs * 1000 $startTime = TimerInit() While TimerDiff($startTime) < $waitSecs sleep(100) $result =_ImageSearch($findImage, $resultPosition, $x, $y, $tolerance) if $result > 0 Then return 1 EndIf WEnd return 0 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for any of a set of ; images to appear ; ; Syntax: _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the ARRAY of images to locate on the desktop ; - ARRAY[0] is set to the number of images to loop through ; ARRAY[1] is the first image ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns the index of the successful find ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance) $waitSecs = $waitSecs * 1000 $startTime = TimerInit() While TimerDiff($startTime) < $waitSecs for $i = 1 to $findImage[0] sleep(100) $result =_ImageSearch($findImage[$i], $resultPosition, $x, $y, $tolerance) if $result > 0 Then return $i EndIf Next WEnd return 0 EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2014 Share Posted July 31, 2014 (edited) I do not see any recursion in that function. Possibly your own code and just happened to tap out there. Edited July 31, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
giorgio007 Posted July 31, 2014 Author Share Posted July 31, 2014 I run this code. After half an hour, i get error message.... expandcollapse popupHotKeySet("{F1}", "Start") HotKeySet("{F2}", "Pause") HotKeySet("{F3}", "_Exit") Global $x = 0 Global $y = 0 Global $x2 = 0 Global $y2 = 0 Global $x3 = 0 Global $y3 = 0 Global $x4 = 0 Global $y4 = 0 Global $x5 = 0 Global $y5 = 0 Global $x6 = 0 Global $y6 = 0 Global $hpx = 0 Global $hpy = 0 Global $hplx = 0 Global $hply = 0 Global $gatex = 0 Global $gatey = 0 Global $mapx = 0 Global $mapy = 0 Global $portx = 0 Global $porty = 0 Global $bugx = 0 Global $bugy = 0 Global $shildx = 0 Global $shildy = 0 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ImageSearch.au3> $main_form = GUICreate("", 172, 291, 562, 190) GUISetFont(10, 400, 0, "Verdana") $hotkeys_g = GUICtrlCreateGroup("Hotkeys", 8, 0, 153, 89) $txt_start = GUICtrlCreateLabel("F1 = Start", 16, 16, 73, 20) $txt_pause = GUICtrlCreateLabel("F2 = Pause", 16, 40, 78, 20) $txt_exit = GUICtrlCreateLabel("F3 = Exit", 16, 64, 63, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) $set_g = GUICtrlCreateGroup("Settings", 8, 88, 153, 169) $bb_cx = GUICtrlCreateCheckbox("Box1", 16, 112, 105, 17) GUICtrlSetState($bb_cx, $GUI_CHECKED) $ranfly_cx = GUICtrlCreateCheckbox("Box2", 16, 136, 97, 17) GUICtrlSetState($ranfly_cx, $GUI_CHECKED) $mstxt = GUICtrlCreateLabel("Wait between", 16, 160, 139, 20) $msip = GUICtrlCreateInput("2000", 16, 184, 49, 24) $ms = GUICtrlCreateLabel("Milliseconds", 72, 186, 81, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) $cx_attesc = GUICtrlCreateCheckbox("Box3", 16, 232, 121, 17) GUICtrlSetState($cx_attesc, $GUI_CHECKED) GUICtrlSetState($cx_attesc, $GUI_DISABLE) $logo = GUICtrlCreateLabel("www.facebook.com", 24, 264, 123, 22) GUICtrlSetFont(-1, 12, 400, 0, "Verdana") $cx_logs = GUICtrlCreateCheckbox("Relog", 16, 208, 121, 25) GUICtrlSetState($cx_logs, $GUI_CHECKED) GUICtrlSetState($cx_logs, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Main() Func Main() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $logo ShellExecute("www.facebook.com") Main() EndSwitch WEnd EndFunc Func Start();Start up Global $mPos = MouseGetPos() Global $rBB = GUICtrlRead($bb_cx) Global $rRan = GUICtrlRead($ranfly_cx) Global $rMS = GUICtrlRead($msip) If $rBB = 1 Then Else MsgBox(48,"Error","Please enable Box1") Main() EndIf If $rMS < 499 or $rMS > 4001 or "" Then MsgBox(48,"Error","Please enter wait time between(Min 500 : Max 4000)") Main() Else EndIf If $rRan = 1 Then Else MsgBox(48,"Error","Please enable Box3") Main() EndIf _check_bkmap() EndFunc Func _check_bkmap() While 1 $bkmap = _ImageSearch("1.bmp",1,$mapx,$mapy,0) If $bkmap = 1 Then _Lock() Else ToolTip("black)",0,0,"") Sleep(500) EndIf WEnd EndFunc Func _Lock();Locates $minimap = _ImageSearch("2.bmp",1,$x,$y,0) If $minimap = 1 Then _shild() Else ToolTip("not found",0,0,"") Sleep(2000) _Lock() EndIf EndFunc Func _shild();Checks shield $shild = _ImageSearch("3.bmp",1,$shildx,$shildy,0) If $shild = 1 Then _hp_check() Else ToolTip("not fully",0,0,"") Sleep(500) _Lock() EndIf EndFunc Func _hp_check();Checks $hp = _ImageSearch("3.bmp",1,$hpx,$hpy,0) If $hp = 1 Then _AutoFly() Else ToolTip("not found",0,0,"") Sleep(500) _Lock() EndIf EndFunc Func _AutoFly();Random ToolTip("",0,0,"") $rMS = GUICtrlRead($msip) $wait = $rMS MouseClick("left",$x+(Random(0,180,1)),$y+(Random(0,110,1)),1,1) MouseMove($mPos[0],$mPos[1],0) Sleep(500) hp_att() EndFunc Func hp_att();Check $hp_att = _ImageSearch("4.bmp",1,$hplx,$hply,0) If $hp_att = 1 Then _finder() Else $jumpgate = _ImageSearch("5.bmp",1,$gatex,$gatey,0) If $jumpgate = 1 Then MouseClick("left",$gatex,$gatey,1,0) MouseMove($mPos[0],$mPos[1],0) _get_gate() EndIf EndIf EndFunc Func _relog();Check if you have been disconnected with the server $rLog = GUICtrlRead($cx_logs) If $rLog = 1 Then $r_log = _ImageSearch("reloggin.bmp",1,$x4,$y4,100) If $r_log = 1 Then MouseClick("left",$x4,$y4,1,1) hp_att() EndIf Else hp_att() EndIf EndFunc Func _finder();Searches $rMS = GUICtrlRead($msip) $wait = $rMS Global $int = 0 While 1 $bb = _ImageSearch("6.bmp",1,$x2,$y2,100) If $bb = 1 Then MouseClick("left",$x2+10,$y2,1,3) Sleep($wait) _Check_hp2() Else $maplocPos = _ImageSearch("7.bmp",1,$x5,$y5,0) If $maplocPos = 1 Then _AutoFly() Else _Check_bugs() EndIf EndIf WEnd EndFunc Func _Check_bugs() $error_bugs = _ImageSearch("8.bmp",1,$bugx,$bugy,0) If $error_bugs = 1 Then _finder() Else _AutoFly() EndIf EndFunc Func _Check_hp2();Check $hp_att = _ImageSearch("8.bmp",1,$hplx,$hply,0) If $hp_att = 1 Then _Check_collect() Else $jumpgate = _ImageSearch("9.bmp",1,$gatex,$gatey,0) If $jumpgate = 1 Then MouseClick("left",$gatex,$gatey,1,0) MouseMove($mPos[0],$mPos[1],0) _get_gate() EndIf EndIf EndFunc Func _Check_collect();Collect $rMS = GUICtrlRead($msip) $wait = $rMS While 1 $c_bb = _ImageSearch("10.bmp",1,$x3,$y3,100) If $c_bb = 1 Then MouseClick("left",$x3,$y3,1,3) _Check_hp3() Else _AutoFly() EndIf WEnd EndFunc Func _Check_hp3();Check $hp_att = _ImageSearch("11.bmp",1,$hplx,$hply,0) If $hp_att = 1 Then _Wait_timer() Else $jumpgate = _ImageSearch("12.bmp",1,$gatex,$gatey,0) If $jumpgate = 1 Then MouseClick("left",$gatex,$gatey,1,0) MouseMove($mPos[0],$mPos[1],0) _get_gate() EndIf EndIf EndFunc Func _Wait_timer();Waits till $rMS = GUICtrlRead($msip) $wait = $rMS While 1 $staub = _ImageSearch("13.bmp",1,$x6,$y6,100) If $staub = 1 Then Sleep($wait) _Check_collect() Else _Check_collect() EndIf WEnd EndFunc Func _get_gate();Lock $rMS = GUICtrlRead($msip) $wait = $rMS While 1 $jumpArv = _ImageSearch("14.bmp",1,$portx,$porty,100) If $jumpArv = 1 Then Send("{j}") _rep_hp() Else _recheck() EndIf WEnd EndFunc Func _recheck();Check $reHP = _ImageSearch("15.bmp",1,$hplx,$hply,0) If $reHP = 1 Then _AutoFly() Else _get_gate() EndIf EndFunc Func _rep_hp();Waits till $rMS = GUICtrlRead($msip) $wait = $rMS While 1 $rep_hp = _ImageSearch("16.bmp",1,$hplx,$hply,0) If $rep_hp = 1 Then Sleep($wait) _Lock() Else EndIf WEnd EndFunc Func Pause();Pauses script While 1 Sleep(300) WEnd EndFunc Func _Exit();Exit script Exit EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted July 31, 2014 Share Posted July 31, 2014 Crikey! Don't know where to start, that is recursion overload. Do you know what recursion is? You should look it up. For starters,do not call main from within main, infact I'd get rid of main and just run while loop globaly, calling start from the button or whatever it is. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Danp2 Posted July 31, 2014 Share Posted July 31, 2014 What game are you trying to automate? Latest Webdriver UDF Release Webdriver Wiki FAQs 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