ArtoAllan Posted March 7, 2020 Share Posted March 7, 2020 Hey guys. I am having a issues with the script below. I am using pixelsearch and if BOTH these pixelsearches gives error it should do the "Then". but for some reason it only reacts to the first pixelsearch and ignores the second one. Can anyone tell me why and what I am doing wrong? $pos=PixelSearch(1580, 529,1580, 529,0x484A3F, 1) and $pos=PixelSearch(1594, 579,1594, 579,0x3E423F, 1); If @error Then Link to comment Share on other sites More sharing options...
Developers Jos Posted March 7, 2020 Developers Share Posted March 7, 2020 Well... that first line does not really make any sense! Make it 2 seperate lines and save the returned @error value, and then test for it. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ArtoAllan Posted March 7, 2020 Author Share Posted March 7, 2020 6 minutes ago, Jos said: Well... that first line does not really make any sense! Make it 2 seperate lines and save the returned @error value, and then test for it. Jos Brother.. I have no idea what you just said. Like this? $pos=PixelSearch(1580, 529,1580, 529,0x484A3F, 1) If @error Then $pos=PixelSearch(1594, 579,1594, 579,0x3E423F, 1) If @error Then Link to comment Share on other sites More sharing options...
Developers Jos Posted March 7, 2020 Developers Share Posted March 7, 2020 (edited) 19 minutes ago, ArtoAllan said: Brother.. Brother ? .... doubt that. 19 minutes ago, ArtoAllan said: I have no idea what you just said. Like this? Why don't you try a little harder to code valid syntax instead of dumping it here and hoping we do it for you? Open the Helpfile and read on how to code valid statements and run au3check to check your code. Jos Edited March 7, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
AutoBert Posted March 7, 2020 Share Posted March 7, 2020 1 hour ago, ArtoAllan said: Brother.. I have no idea what you just said. Like this? For example like this: $bDoIt = True $pos = PixelSearch(1580, 529, 1580, 529, 0x484A3F, 1) If Not @error Then $bDoIt = False If $bDoIt Then $pos2 = PixelSearch(1594, 579, 1594, 579, 0x3E423F, 1) If Not @error Then $bDoIt = False EndIf If $bDoIt Then ;here the stuff what' to be done Else ;something else EndIf Link to comment Share on other sites More sharing options...
ModemJunki Posted March 9, 2020 Share Posted March 9, 2020 Do you need to put the array from PixelSearch to use later in your code? If so then maybe something like: $a_pos = PixelSearch(1580, 529, 1580, 529, 0x484A3F, 1) $a_pos2 = PixelSearch(1594, 579, 1594, 579, 0x3E423F, 1) If Not IsArray($a_pos) And Not IsArray($a_pos2) Then ConsoleWrite("Neither are an array, and so PixelSearch found nothing." & @CRLF) Else ConsoleWrite("PixelSearch did return an array." & @CRLF) EndIf If not then you can: If Not IsArray(PixelSearch(1580, 529, 1580, 529, 0x484A3F, 1)) And Not IsArray(PixelSearch(1594, 579, 1594, 579, 0x3E423F, 1)) Then ConsoleWrite("Neither are an array, and so PixelSearch found nothing." & @CRLF) Else ConsoleWrite("PixelSearch did return an array." & @CRLF) EndIf Of course if you don't need the Else you can make a one-line If..Then with your call to an action. @AutoBert, I tested with your script and it didn't work for me because you had declared a value for $bDoIt and thus it was always returning true for the If statement. I made a small correction and now this works but it's not how I would do it. Global $bDoIt $pos = PixelSearch(1580, 529, 1580, 529, 0x484A3F, 1) If Not @error Then $bDoIt = False If $bDoIt Then $pos2 = PixelSearch(1594, 579, 1594, 579, 0x3E423F, 1) If Not @error Then $bDoIt = False EndIf If $bDoIt Then ConsoleWrite("$bDoIt true" & @CRLF);here the stuff what' to be done Else ConsoleWrite("$bDoIt false" & @CRLF);here the stuff what' to be done EndIf If I wanted to capture the @error value I'd: $a_pos = PixelSearch(1580, 529, 1580, 529, 0x484A3F, 1) If @error Then $a_pos = @error $a_pos2 = PixelSearch(1594, 579, 1594, 579, 0x3E423F, 1) If @error Then $a_pos2 = @error If $a_pos = 1 And $a_pos2 = 1 Then ConsoleWrite("Both have the same value of 1 which should only happen when there are errors." & @CRLF) Else ConsoleWrite("something else" & @CRLF) EndIf Always carry a towel. 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