exevan Posted May 3, 2014 Share Posted May 3, 2014 (edited) Hello, so i use this function: Func Pixel_Distance($x1, $y1, $x2, $y2) If $x2 = $x1 And $y2 = $y1 Then Return 0 Else $a = $y2 - $y1 $b = $x2 - $x1 $c = Sqrt($a * $a + $b * $b) Return $c EndIf EndFunc Func DrawLine($start_x, $start_y, $end_x, $end_y, $color) Global $hDC, $hPen, $obj_orig $hDC = _WinAPI_GetWindowDC(0) $hPen = _WinAPI_CreatePen($PS_SOLID, 1, $color) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) _WinAPI_DrawLine($hDC, $start_x, $start_y, $end_x, $end_y) _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) EndFunc Func _Test() while 1 Local $FirstFile = PixelSearch(389, 76,1540, 870,0xF6F2D9) Local $SecondFile = PixelSearch(389, 76,1540, 870,0xDA7714) if not @error then Pixel_Distance($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1]) DrawLine($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1], 0x00) _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) ToolTip("Distance: "&$c,0,0) sleep(1000) else ContinueLoop endif wend EndFunc After 15 or 20 seconds i've got a error: Pixel_Distance($FirstFile[0],...) $FirstFile ^ ERROR Error: Subscrit used on non accesible variable What's wrong? And next question is about WinApi My function draw a line on desktop every one second. How can i delete last line before a new line is draw? Edited May 3, 2014 by exevan Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 1) Because PixelSearch fails 2) _WinAPI_RedrawWindow exevan 1 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 So what i must do when the pixelsearch is failed? i try this: Func _Test() while 1 Local $FirstFile = PixelSearch(389, 76,1540, 870,0xF6F2D9) Local $SecondFile = PixelSearch(389, 76,1540, 870,0xDA7714) if not @error then Pixel_Distance($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1]) DrawLine($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1], 0x00) _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) ToolTip("Distance: "&$c,0,0) sleep(1000) else _Test() endif wend EndFunc but doesn't work;/ Link to comment Share on other sites More sharing options...
JohnOne Posted May 3, 2014 Share Posted May 3, 2014 This if not @error then Needs to changed to test that both $firstfile and $secondfile are arrays (IsArray() function). You can leave continueloop and get shut of recursive _Test() exevan 1 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...
exevan Posted May 3, 2014 Author Share Posted May 3, 2014 (edited) Thanks Now with this clean previous draw line ;/ Edited May 3, 2014 by exevan 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