computergroove Posted July 27, 2014 Share Posted July 27, 2014 I just completed my largest script to date - and it doesn't work. I have added a msgbox so I know the while loop is working. I am guessing that the Local variables are not refreshing during the loop. What I want is all the variables to constantly check for color changes at different coordinates and if a color changes to match the coordinates then the script will click on it. expandcollapse popupFunc WorkHorse() MouseClick("Left",51,84,1) MouseClick("Left",375,84,1) MouseClick("Left",706,88,1) While 1 Local $NV1 = PixelGetColor(38,351) Local $NV2 = PixelGetColor(372,351) Local $NV3 = PixelGetColor(698,351) Local $B511 = PixelGetColor(261,403) Local $B512 = PixelGetColor(261,435) Local $B513 = PixelGetColor(261,467) Local $B521 = PixelGetColor(591,403) Local $B522 = PixelGetColor(591,435) Local $B523 = PixelGetColor(591,467) Local $B531 = PixelGetColor(916,403) Local $B532 = PixelGetColor(916,435) Local $B533 = PixelGetColor(916,467) Local $WV1 = PixelGetColor(32,192) Local $WV2 = PixelGetColor(412,192) Local $WV3 = PixelGetColor(743,192) Local $WX1 = PixelGetColor(311,47) Local $WX2 = PixelGetColor(627,62) Local $DB1 = PixelGetColor(30,74) Local $DB2 = PixelGetColor(354,74) Local $DB3 = PixelGetColor(681,74) Local $EP1 = PixelGetColor(216,314) ;It doesn't do any of the commands below this line but if I put a msgbox here it works. If $NV1 == 4821505 Then MouseClick("Left",38,351,1) Sleep(100) ElseIf $NV2 == 4821505 Then MouseCLick("Left",372,351,1) Sleep(100) ElseIf $NV3 == 4821505 Then MouseCLick("Left",698,351,1) Sleep(100) ElseIf $B511 == 28159 Then MouseClick("Left",261,403,1) Sleep(100) ElseIf $B512 == 28159 Then MouseClick("Left",261,435,1) Sleep(100) ElseIf $B513 == 28159 Then MouseClick("Left",261,467,1) Sleep(100) ElseIf $B521 == 28159 Then MouseClick("Left",261,403,1) Sleep(100) ElseIf $B522 == 28159 Then MouseClick("Left",261,435,1) Sleep(100) ElseIf $B523 == 28159 Then MouseClick("Left",261,467,1) Sleep(100) ElseIf $B531 == 28159 Then MouseClick("Left",261,403,1) Sleep(100) ElseIf $B532 == 28159 Then MouseClick("Left",261,435,1) Sleep(100) ElseIf $B533 == 28159 Then MouseClick("Left",261,467,1) Sleep(100) ElseIf $WV1 == 14398976 Then MouseClick("Left",32,187,1) Sleep(100) ElseIf $WV2 == 14398976 Then MouseClick("Left",412,192,1) Sleep(100) ElseIf $WV3 == 28159 Then MouseClick("Left",743,192,1) Sleep(100) ElseIf $WX1 == 16777215 Then MouseClick("Left",311,47,1) Sleep(100) ElseIf $WX2 == 16777215 Then MouseClick("Left",627,62,1) Sleep(100) ElseIf $DB1 == 2387455 Then MouseClick("Left",30,74,1) Sleep(100) ElseIf $DB2 == 2387455 Then MouseClick("Left",354,74,1) Sleep(100) ElseIf $DB3 == 2387455 Then MouseClick("Left",681,74,1) Sleep(100) EndIf WEnd EndFunc I'm sure it's a logic issue of some sort. Each local variable corresponds to a specific click event. I thought this was a good idea. Any suggestions? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
tommytx Posted July 27, 2014 Share Posted July 27, 2014 Do you know for a fact that the top part is working... is any of them finding the color.. why not put something like this to see.. Local $NV1 = PixelGetColor(38,351) consolewrite($NV1) Local $NV2 = PixelGetColor(372,351) consolewrite($NV2) Local $NV3 = PixelGetColor(698,351) consolewrite($NV3) would only take a few seconds to cut and paste this in.. to make sure some colors are showing up.... or even just add $NV3 == 4821505 as this would make one of the top items valid.. so that forces the top to work.. now with the forced variable does the bottom work. Link to comment Share on other sites More sharing options...
tommytx Posted July 27, 2014 Share Posted July 27, 2014 oops sorry... or even just add $NV3 == 4821505 as this would should be this.. or even just add $NV3 = 4821505 as this would Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 27, 2014 Share Posted July 27, 2014 ya, try ='s instead of =='s. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
computergroove Posted July 27, 2014 Author Share Posted July 27, 2014 (edited) MsgBox(0,"Results", $NV1 & @CRLF & $NV2 & @CRLF & $NV3 & @CRLF & $B511 & @CRLF & $B512 & @CRLF & $B513 & @CRLF & $B521 & @CRLF & $B522 & @CRLF & $B523 & @CRLF & $B531 & @CRLF & $B532 & @CRLF & $B533 & @CRLF & $WV1 & @CRLF & $WV2 & @CRLF & $WV3 & @CRLF & $WX1 & @CRLF & $WX2 & @CRLF & $DB1 & @CRLF & $DB2 & @CRLF & $DB3 & @CRLF & $EP1) The above produces several different numbers. When I click OK some of the numbers change. If I click OK again some of the numbers change(The screen is changing which is changing the numbers) so I know its reading the numbers and even refreshing them as things change on the screen. Why wont autoit execute the mouseclick functions in the while loop? Edited July 27, 2014 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
computergroove Posted July 27, 2014 Author Share Posted July 27, 2014 I tried "=" instead of "==" and it still doesn't work. I think == is the right syntax for comparing a variable to a string. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 27, 2014 Share Posted July 27, 2014 try making each ElseIf it's own If, closing each one above it of course, with an EndIf. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Geir1983 Posted July 27, 2014 Share Posted July 27, 2014 (edited) I tried "=" instead of "==" and it still doesn't work. I think == is the right syntax for comparing a variable to a string. PixelGetColor returns a integer value, you also compare it to an integer value. A string is enclosed in " signs. You realy should look into loops and arrays, your script would be alot nicer, see the example below: #include <array.au3> Global Enum $eClolorCode, $eSearchX, $eSearchY Local $arrSearch[0][3] _ArrayAdd($arrSearch, "4821505|38|351") ; Make a line like this for every pixel to search and click _ArrayAdd($arrSearch, "4821505|372|351") WorkHorse() Func WorkHorse() MouseClick("Left",51,84,1) MouseClick("Left",375,84,1) MouseClick("Left",706,88,1) While 1 For $idx=0 to UBound($arrSearch)-1 IF PixelGetColor($arrSearch[$idx][$eSearchX], $arrSearch[$idx][$eSearchY]) = $arrSearch[$idx][$eClolorCode] Then MouseClick("Left",$arrSearch[$idx][$eSearchX],$arrSearch[$idx][$eSearchY],1) Sleep(100) EndIf Next Sleep(10) WEnd EndFunc Edited July 27, 2014 by Geir1983 Link to comment Share on other sites More sharing options...
computergroove Posted July 27, 2014 Author Share Posted July 27, 2014 PixelGetColor returns a integer value, you also compare it to an integer value. A string is enclosed in " signs. You realy should look into loops and arrays, your script would be alot nicer, see the example below: #include <array.au3> Global Enum $eClolorCode, $eSearchX, $eSearchY Local $arrSearch[0][3] _ArrayAdd($arrSearch, "4821505|38|351") ; Make a line like this for every pixel to search and click _ArrayAdd($arrSearch, "4821505|372|351") WorkHorse() Func WorkHorse() MouseClick("Left",51,84,1) MouseClick("Left",375,84,1) MouseClick("Left",706,88,1) While 1 For $idx=0 to UBound($arrSearch)-1 IF PixelGetColor($arrSearch[$idx][$eSearchX], $arrSearch[$idx][$eSearchY]) = $arrSearch[$idx][$eClolorCode] Then MouseClick("Left",$arrSearch[$idx][$eSearchX],$arrSearch[$idx][$eSearchY],1) Sleep(100) EndIf Next Sleep(10) WEnd EndFunc Arrays: Pros: 1. Smaller footprint of code Cons: 1. People that don't understand arrays wont be able to assist me as I develop my code so I will get no responses to my forum posts. 2. With the way I had the variables set before I could replace values on the fly and not take up more memory *if I'm reading the code correctly) with this array adding variables on the fly I don't think I can. The above code with the data added still does nothing. After looking at the code it appears that the while loop doesn't allow the variables to update as the screen changes. My other one did but stopped at any attempt at clicking a mouse. You are using _Arrayadd, If I add an array to to overwrite an existing array will get a memory leak? The way I had it coded before worked for the variable assignment and it didn't use a ton of memory. Am I thinking right about this? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Geir1983 Posted July 27, 2014 Share Posted July 27, 2014 (edited) Uhm, arrays dont take up more memory and of course you can change them "on the fly". You say you could change the variables "on the fly" in your original code, but there you use constant values instead of variables, changing the value in your OP means changing the code itself. If you want to change an line in the array you dont add another line, you just change the values inside it. Sorry had an error in the example, _ArrayAdd dont work that way.. Try this #include <array.au3> Global Enum $eClolorCode, $eSearchX, $eSearchY Local $arrSearch[0][3] _AddSearch($arrSearch, 4821505, 38, 351) ; Make a line like this for every pixel to search and click _AddSearch($arrSearch, 4821505, 372, 351) Func _AddSearch(ByRef $arrSearch, $color, $x, $y) ReDim $arrSearch[UBound($arrSearch)+1][UBound($arrSearch, 2)] ;Increase dimension $arrSearch[UBound($arrSearch)-1][$eClolorCode] = $color $arrSearch[UBound($arrSearch)-1][$eSearchX] = $x $arrSearch[UBound($arrSearch)-1][$eSearchY] = $y EndFunc WorkHorse() Func WorkHorse() MouseClick("Left",51,84,1) MouseClick("Left",375,84,1) MouseClick("Left",706,88,1) While 1 For $idx=0 to UBound($arrSearch)-1 $tempColor = PixelGetColor($arrSearch[$idx][$eSearchX], $arrSearch[$idx][$eSearchY]) ;ConsoleWrite("Searching for color: " & $arrSearch[$idx][$eClolorCode] & " found color: " & $tempColor & " at location " & $arrSearch[$idx][$eSearchX]& "," & $arrSearch[$idx][$eSearchY] & @crlf) IF $tempColor = $arrSearch[$idx][$eClolorCode] Then MouseClick("Left",$arrSearch[$idx][$eSearchX],$arrSearch[$idx][$eSearchY],1) Sleep(100) EndIf Next Sleep(10) WEnd EndFunc Edited July 27, 2014 by Geir1983 Link to comment Share on other sites More sharing options...
computergroove Posted July 27, 2014 Author Share Posted July 27, 2014 I am injecting this into a script with multiple functions. Can you explain why Enum $eClolorCode, $eSearchX, $eSearchY are set as global variables but directly under it the $arraysearch[0][3] is set as local in the global position? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
computergroove Posted July 27, 2014 Author Share Posted July 27, 2014 The above modified code did not work. I went back to my original code without using an array and I started editing out some lines to see what would happen. It behaves the same way whether I separate the if statements or not. It appears that the script will perform a mouseclick when one of the coordinates finds that the color matches but it stops there. The variables keep updating but the program wont mouseclick any other locations. I am baffled. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Geir1983 Posted July 28, 2014 Share Posted July 28, 2014 I like to have enums as Global (because they will work also in other scripts you include), the array i would only use in this script, thats why i used Local. I dont see why the example i posted wont work, my guess is the color is not an exact match. You can uncomment the Consolewrite inside the function to see what colors it finds and what its matching it against. In your OP you have Elseif's meaning it will only execute the first click function that matches in that If / ElseIf. 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