B4ckBOne Posted January 23, 2015 Posted January 23, 2015 (edited) Hi all, im new but i have been scripting and reading for some time now. At the moment im trying to do some motion detection and shape recognition for fun and exercise. I have an area of 1024 by 769 pixels which i want to read into an array and do some stuff from there. Here is my script: expandcollapse popupHotKeySet("{PGDn}","_Exit") HotKeySet("{ins}","Search") Dim $Bild1[1025][769] Dim $Bild2[1025][769] $height = 1024 $width = 769 $diff = 0 $x = 0 $x = 0 $x1 = 0 $y1 = 0 $counter = 0 $click = 0 Func Search() ;Bild einlesen While 1 For $x = 0 To $height Step +50 ;ConsoleWrite ($counter & @CRLF) For $y = 0 To $width Step +50 $Bild1[$x][$y] = PixelGetColor($x, $y) ;ConsoleWrite ($Bild1[$x][$y] &" " &$x &" " &$y& " " & @CRLF) Next Next For $i = 0 to 5000 Step +1 $x = 0 $x = 0 ;ConsoleWrite ($counter & @CRLF) ;Bild2 einlesen For $x = 0 To $height Step +50 For $y = 0 To $width Step +50 $Bild2[$x][$y] = PixelGetColor($x, $y) If $Bild2[$x][$y] <> $Bild1[$x][$y] Then $x = $x1 $y = $y1 $diff = $diff + 1 EndIf Next Next If $diff > 0 and $diff < 5 Then ConsoleWrite ("found" & $diff & @CRLF) MouseClick("left",$x1, $y1, 2, 0) ConsoleWrite ("found" & $diff & @CRLF) Sleep(100) EndIf $diff = 0 $counter = $counter + 1 ConsoleWrite ($counter & @CRLF) Next if $click = 0 Then MouseClick("left", 810,230,1,0) Sleep(1750) EndIf if $click = 1 Then MouseClick("left", 710,230,1,0) Sleep(1750) EndIf ;if $click = 2 Then ; MouseClick("left", 630,230,1) ;EndIf if $click = 3 Then MouseClick("left", 550,230,1,0) Sleep(1750) EndIf if $click = 4 Then MouseClick("left", 460,230,1,0) Sleep(1750) EndIf if $click = 5 Then MouseClick("left", 350,230,1,0) Sleep(1750) EndIf ;if $click = 6 Then ; MouseClick("left", 350,230,1) ;EndIf if $click = 7 Then MouseClick("left", 270,230,1,0) Sleep(1750) EndIf if $click = 8 Then MouseClick("left", 210,230,1,0) Sleep(1750) $click = 0 EndIf $click = $click + 1 WEnd EndFunc While 1 sleep(500) Wend Func _Exit() Exit EndFunc But it always gets stuck without any error messeages. What am i doing wrong? Edited January 24, 2015 by B4ckBOne
B4ckBOne Posted January 23, 2015 Author Posted January 23, 2015 (edited) So i have continued to work on my script and i ran in to something i cant overcome :-/ It gets stuck without telling me why. So here is what it does: It writes the pixel color of every 50th vertical and horizontal pixel on a 1024x769 screen. Thus creating an arry of pixelcolors all over the screen. Then it compares the Array to a new array at a later time and checks if there has been changes. If changes detected it clicks on the x and y position the change has been detected. And then it does some clicks from time to time which work... Here is what it does not: it does not click and gets stuck and stops running the while loop. Now i cant determine where exactly it gets stuck and why. How you can help if you want to: Tell me why and where it stops. expandcollapse popupHotKeySet("{PGDn}","_Exit") HotKeySet("{ins}","Search") Dim $Bild1[1025][769] Dim $Bild2[1025][769] $height = 1024 $width = 769 $diff = 0 $x = 0 $x = 0 $x1 = 0 $y1 = 0 $counter = 0 $click = 0 Func Search() ;Bild einlesen While 1 For $x = 0 To $height Step +50 ;ConsoleWrite ($counter & @CRLF) For $y = 0 To $width Step +50 $Bild1[$x][$y] = PixelGetColor($x, $y) ;ConsoleWrite ($Bild1[$x][$y] &" " &$x &" " &$y& " " & @CRLF) Next Next For $i = 0 to 5000 Step +1 $x = 0 $x = 0 ;ConsoleWrite ($counter & @CRLF) ;Bild2 einlesen For $x = 0 To $height Step +50 For $y = 0 To $width Step +50 $Bild2[$x][$y] = PixelGetColor($x, $y) If $Bild2[$x][$y] <> $Bild1[$x][$y] Then $x = $x1 $y = $y1 $diff = $diff + 1 EndIf Next Next If $diff > 0 and $diff < 5 Then ConsoleWrite ("found" & $diff & @CRLF) MouseClick("left",$x1, $y1, 2, 0) ConsoleWrite ("found" & $diff & @CRLF) Sleep(100) EndIf $diff = 0 $counter = $counter + 1 ConsoleWrite ($counter & @CRLF) Next if $click = 0 Then MouseClick("left", 810,230,1,0) Sleep(1750) EndIf if $click = 1 Then MouseClick("left", 710,230,1,0) Sleep(1750) EndIf ;if $click = 2 Then ; MouseClick("left", 630,230,1) ;EndIf if $click = 3 Then MouseClick("left", 550,230,1,0) Sleep(1750) EndIf if $click = 4 Then MouseClick("left", 460,230,1,0) Sleep(1750) EndIf if $click = 5 Then MouseClick("left", 350,230,1,0) Sleep(1750) EndIf ;if $click = 6 Then ; MouseClick("left", 350,230,1) ;EndIf if $click = 7 Then MouseClick("left", 270,230,1,0) Sleep(1750) EndIf if $click = 8 Then MouseClick("left", 210,230,1,0) Sleep(1750) $click = 0 EndIf $click = $click + 1 WEnd EndFunc While 1 sleep(500) Wend Func _Exit() Exit EndFunc Edited January 24, 2015 by B4ckBOne
Bert Posted January 24, 2015 Posted January 24, 2015 What is this script ran against? (name of the application please) I ask for pixel searching is horrible in most cases to solve a problem. Usually there is a better way than pixel searching. I see you are German so I'm putting the same thing in German as well Was ist das Skript lief gegen ? ( Name der Anwendung, bitte ) Ich bitte um Pixelsuch ist schrecklich in den meisten Fällen , um ein Problem zu lösen . In der Regel gibt es einen besseren Weg, als Pixelsuch . The Vollatran project My blog: http://www.vollysinterestingshit.com/
B4ckBOne Posted January 24, 2015 Author Posted January 24, 2015 The script is runing against a static website that has a floating object apearing randomly and moving around in a random pattern. Therefore i have come up with this "Minefield" of pixelsearch points that when a point is triggered should be clicked. But at the moment the script just stops working from time to time without an error. Maybe the clicking does not work or the reserved memory is full etc.. But it does not spit out any errors. Thats why i put in the console write, to see the cycles and weathor or not it wants to trigger a click event before it stops. If the cycle number is not increasing anymore i can detect that the script got stuck. But it never triggered the click event, even when it should. Which confuses me very much. Any help would be appreciated.
Valuater Posted January 24, 2015 Posted January 24, 2015 Dim $Bild1[502][302] for $y can got to 500, however your Array says 302 Maybe switch Dim $Bild1[302][502] 8)
B4ckBOne Posted January 24, 2015 Author Posted January 24, 2015 Thanks Valuater I have corrected that in my second code snippet. Will update the first code too. But the problem stays the same.
Valuater Posted January 24, 2015 Posted January 24, 2015 (edited) For $i = 0 to 5000 Step +1<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Why 5000? $x = 0<<<<<<<<<<<<<<<<< reset once $x = 0<<<<<<<<<<<<<<<<<< reset twice? ;ConsoleWrite ($counter & @CRLF) ;Bild2 einlesen For $x = 0 To $height Step +50 For $y = 0 To $width Step +50 $Bild2[$x][$y] = PixelGetColor($x, $y) If $Bild2[$x][$y] <> $Bild1[$x][$y] Then $x = $x1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< You keep resetting $x to zero... Thus it will never finish $y = $y1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $diff = $diff + 1 EndIf Next Next --------------------------------------------------------------------- Also Why set the same variable to zero twice??? $height = 1024 $width = 769 $diff = 0 $x = 0<<<<<<<<<<<<<<<<<< $x = 0<<<<<<<<<<<<<<<<<< ---------------------------------------------------- I cant test the code... Sorry 8) Edited January 24, 2015 by Valuater
B4ckBOne Posted January 25, 2015 Author Posted January 25, 2015 Thank you very much Valuater Both are coding errors i made. $x1 should have been set to the value of $x and not the other way around. And reset only needs to be done once. The other $x should have been $y
Bert Posted January 25, 2015 Posted January 25, 2015 The script is runing against a static website that has a floating object apearing randomly and moving around in a random pattern.URL please. I ask for you may be able to do this in a different way (as I said before) The Vollatran project My blog: http://www.vollysinterestingshit.com/
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