D3fr0s7 Posted May 7, 2020 Posted May 7, 2020 I'm getting frustrated with having to nest 'If' operations to achieve the same thing that an 'And' operation should. Am I not using the operator correctly? Here is a snippet of example script: $Ax = 800 $Ay = 580 $Bx = 1200 $By = 580 For $X = 1 to 12 $AColor = PixelGetColor ( $Ax, $Ay ) $BColor = PixelGetColor ( $Bx, $By ) ; I've tried these If $AColor = $BColor And $AColor = 0x3336F0 Then ; Code to run ExitLoop EndIf If ( $AColor = $BColor And $AColor = 0x3336F0 ) Then ; Code to run ExitLoop EndIf If ( $AColor = $BColor = 0x3336F0 ) Then ; Code to run ExitLoop EndIf Sleep ( 1000 ) Next It only seems to execute the code if it sees that $Acolor = 0x3336F0 and doesn't wait until $BColor is also equal to that. I can achieve the same thing with nesting 'If' operations but I'm tired of that and want to get to the bottom of why the 'And' functions aren't doing it for me. Any help would be appreciated
faustf Posted May 7, 2020 Posted May 7, 2020 in this mode you have tryed? If ($State <> "Test1") And ($State <> "Test2") Then
water Posted May 7, 2020 Posted May 7, 2020 Why do you think a pixel can have two colors at the same time (assuming that $BColor <> 0x3336F0)? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Nine Posted May 7, 2020 Posted May 7, 2020 If ( $AColor = $BColor = 0x3336F0 ) Then That line doesn't make sense. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
D3fr0s7 Posted May 8, 2020 Author Posted May 8, 2020 4 hours ago, faustf said: in this mode you have tryed? If ($State <> "Test1") And ($State <> "Test2") Then For some reason I did not think to compare one variable to the desired color code, and then the other variable to the desired color code... That fixed my problem! If ( $AColor = 0x111111 ) And ( $BColor = 0x111111 ) Then ; code EndIf And It seems to work like this too. If ( $AColor = 0x111111 And $BColor = 0x111111 ) Then ; code EndIf I guess AutoIt doesn't like comparing PixelGetColor functions? Which is odd because in the test I just ran, I coded this, and it worked the way I thought it would in the first place. $AColor = PixelGetColor ( 800, 800 ) ; Same color as $BColor $BColor = PixelGetColor ( 801, 801 ) ; Same color as $AColor If $AColor = $BColor Then ; code EndIf Which confuses me more, because if that test passed, why wouldn't this one? If ( $AColor = $BColor And $AColor = 0x3336F0 ) Then ; Code to run, assuming $AColor and $BColor are both equal to 0x3336F0 EndIf 3 hours ago, water said: Why do you think a pixel can have two colors at the same time (assuming that $BColor <> 0x3336F0)? I don't, I expect the 'If' statement to return false in that case, so that it only executes the code when those two pixels are compared and are the same color. 3 hours ago, Nine said: If ( $AColor = $BColor = 0x3336F0 ) Then That line doesn't make sense. Thanks for the help. It doesn't make sense. But Neither did the 'And' operator not working as expected, however my reasoning for that bit of code was since the 'And' operator wasn't working, maybe I could compare all 3 values and if they all turn out to be the same, then the 'If' statement would be true. I was flawed in thinking that after testing it. I was thinking that ( $x = $x = $x ) or ( 4 = 4 = 4 ) would be a true statement. Does that mean that ( 0 < $x < 1 ) would be flawed logically too? I just started coding like a week ago and for some reason my test scripts do what I want them to do, but in my main 1700+ line project, it sometimes just doesn't work out the way I thought it would. However, it is working with the 'And' operators when I swapped them out right now, which again, confuses me because they should've worked the first time.
water Posted May 8, 2020 Posted May 8, 2020 Your code is executed as: ; Assume PixelB is red If PixelA is red and PixelA is green Then PixelA can't have two colors at the same time. Maybe you are mixing it up with the "or" operator. Return True when PixelA is red or PixelA is green. Most of the time it is the scripts logic that needs to be fixed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Malkey Posted May 8, 2020 Posted May 8, 2020 (edited) This is supposed to show that (False = False = True) is True. expandcollapse popup; https://www.autoitscript.com/forum/topic/202653-and-logical-operator-not-working-as-expected/?do=findComment&comment=1454621 ; Zero is false, not zero is true. ConsoleWrite( "Not 0 = " & Not 0 & @CRLF) ; -> Not 0 = True Local $AColor = 1 Local $BColor = 1 ConsoleWrite( ($AColor = $BColor = 2) & @CRLF) ; -> True, where, $AColor = $BColor is true, 2 is "not 0" is true. So, true = true is true. ConsoleWrite((($AColor = $BColor) = 3) & @CRLF) ; -> True ConsoleWrite( ($AColor = $BColor = True) & @CRLF) ; -> True Local $BColor = 2 ConsoleWrite( ($AColor = $BColor = 0) & @CRLF) ; -> True, where, $AColor = $BColor is false, 0 is false. So, (false = false) is true. * ConsoleWrite((($AColor = $BColor) = 0) & @CRLF) ; -> True ConsoleWrite( ($AColor = $BColor = False) & @CRLF) ; -> True Local $x = True ConsoleWrite( ($x = $x = $x) & @CRLF) ; -> True, where, $x = $x is true, $x is true. So, true = true is true. ConsoleWrite( (4 = 4 = 4) & @CRLF) ; -> True, where, 4 = 4 is true, 4 is "not 0" is true. So, true = true is true. ; * Show truth table where (False = False) is True. ConsoleWrite(@CRLF & "--------------- Truth Tables -----------------" & @CRLF) ConsoleWrite("A " & @TAB & "B " & @TAB & "A = B (Same Truth table as Ex-NOR)" & @CRLF) For $i = 1 To 4 ConsoleWrite((Mod($i, 2) = 1) & @TAB & ($i <= 2) & @TAB & (Mod($i, 2) = 1 = ($i <= 2)) & @CRLF) Next ; Ref: https://www.electronics-tutorials.ws/logic/logic_8.html ConsoleWrite(@CRLF & "A " & @TAB & "B " & @TAB & "A Ex-NOR B (Exclusive-NOR made from 5 - NAND's, Not BitAND's)" & @CRLF) For $i = 1 To 4 $a = (Mod($i, 2) = 1) $b = ($i <= 2) $ExNOR = (Not (BitAND(Not (BitAND($a, $b)), Not (BitAND(Not (BitAND($a, $a)), Not (BitAND($b, $b))))))) ConsoleWrite($a & @TAB & $b & @TAB & $ExNOR & @CRLF) Next ConsoleWrite(@CRLF & "A " & @TAB & "B " & @TAB & "A And B " & @CRLF) For $i = 1 To 4 ConsoleWrite((Mod($i, 2) = 1) & @TAB & ($i <= 2) & @TAB & (BitAND((Mod($i, 2) = 1), ($i <= 2)) = 1) & @CRLF) Next #cs ; Output:- --------------- Truth Tables ----------------- A B A = B (Same Truth table as Ex-NOR) True True True False True False True False False False False True A B A Ex-NOR B (Exclusive-NOR made from 5 - NAND's, Not BitAND's) True True True False True False True False False False False True A B A And B True True True False True False True False False False False False #ce Edited May 8, 2020 by Malkey "the chalice from the palace has the brew that is true"
D3fr0s7 Posted May 9, 2020 Author Posted May 9, 2020 17 hours ago, water said: Your code is executed as: ; Assume PixelB is red If PixelA is red and PixelA is green Then PixelA can't have two colors at the same time. Maybe you are mixing it up with the "or" operator. Return True when PixelA is red or PixelA is green. Most of the time it is the scripts logic that needs to be fixed. That helps me understand how the script was understanding it, thanks for enlightening me. 12 hours ago, Malkey said: This is supposed to show that (False = False = True) is True. expandcollapse popup; https://www.autoitscript.com/forum/topic/202653-and-logical-operator-not-working-as-expected/?do=findComment&comment=1454621 ; Zero is false, not zero is true. ConsoleWrite( "Not 0 = " & Not 0 & @CRLF) ; -> Not 0 = True Local $AColor = 1 Local $BColor = 1 ConsoleWrite( ($AColor = $BColor = 2) & @CRLF) ; -> True, where, $AColor = $BColor is true, 2 is "not 0" is true. So, true = true is true. ConsoleWrite((($AColor = $BColor) = 3) & @CRLF) ; -> True ConsoleWrite( ($AColor = $BColor = True) & @CRLF) ; -> True Local $BColor = 2 ConsoleWrite( ($AColor = $BColor = 0) & @CRLF) ; -> True, where, $AColor = $BColor is false, 0 is false. So, (false = false) is true. * ConsoleWrite((($AColor = $BColor) = 0) & @CRLF) ; -> True ConsoleWrite( ($AColor = $BColor = False) & @CRLF) ; -> True Local $x = True ConsoleWrite( ($x = $x = $x) & @CRLF) ; -> True, where, $x = $x is true, $x is true. So, true = true is true. ConsoleWrite( (4 = 4 = 4) & @CRLF) ; -> True, where, 4 = 4 is true, 4 is "not 0" is true. So, true = true is true. ; * Show truth table where (False = False) is True. ConsoleWrite(@CRLF & "--------------- Truth Tables -----------------" & @CRLF) ConsoleWrite("A " & @TAB & "B " & @TAB & "A = B (Same Truth table as Ex-NOR)" & @CRLF) For $i = 1 To 4 ConsoleWrite((Mod($i, 2) = 1) & @TAB & ($i <= 2) & @TAB & (Mod($i, 2) = 1 = ($i <= 2)) & @CRLF) Next ; Ref: https://www.electronics-tutorials.ws/logic/logic_8.html ConsoleWrite(@CRLF & "A " & @TAB & "B " & @TAB & "A Ex-NOR B (Exclusive-NOR made from 5 - NAND's, Not BitAND's)" & @CRLF) For $i = 1 To 4 $a = (Mod($i, 2) = 1) $b = ($i <= 2) $ExNOR = (Not (BitAND(Not (BitAND($a, $b)), Not (BitAND(Not (BitAND($a, $a)), Not (BitAND($b, $b))))))) ConsoleWrite($a & @TAB & $b & @TAB & $ExNOR & @CRLF) Next ConsoleWrite(@CRLF & "A " & @TAB & "B " & @TAB & "A And B " & @CRLF) For $i = 1 To 4 ConsoleWrite((Mod($i, 2) = 1) & @TAB & ($i <= 2) & @TAB & (BitAND((Mod($i, 2) = 1), ($i <= 2)) = 1) & @CRLF) Next #cs ; Output:- --------------- Truth Tables ----------------- A B A = B (Same Truth table as Ex-NOR) True True True False True False True False False False False True A B A Ex-NOR B (Exclusive-NOR made from 5 - NAND's, Not BitAND's) True True True False True False True False False False False True A B A And B True True True False True False True False False False False False #ce Thanks for the reference to help me understand what you were showing through code but it was a little more confusing than what you coded. However, at that point and with the reference in mind it seems I created a 3 input Ex-NOR gate which would explain why the code would execute when either one or the other color was equal to the color desired to execute the code. Thanks for the help, I have a question for another script but I will post that in a new thread later as it will be going off tangent to the topic here!
Moderators JLogan3o13 Posted May 9, 2020 Moderators Posted May 9, 2020 And no one has mentioned the most obvious fix - find a smarter way to do what you're after than pixelsearch. With all the functions and UDFs available, there should be very little reason to have to resort to such unreliable code as this. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
water Posted May 9, 2020 Posted May 9, 2020 Agreed. I just wanted to give the OP the opportunity to understand the difference between logical And and Or My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Moderators JLogan3o13 Posted May 9, 2020 Moderators Posted May 9, 2020 Yup, and you did a great job at it as always @water. Just wanted to throw out there that the OP is causing himself needless pain "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
water Posted May 9, 2020 Posted May 9, 2020 Couldn't agree more My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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