Sign in to follow this  
Followers 0
demonachize

joining multiple functions

4 posts in this topic

I have a need to look for a pixel color in one place while it doesn't exist in two other places. I am trying to use:

While PixelGetColor(1579, 546) = 0xFFDE4B and not PixelGetColor(1820, 735) = 0xFFDE4B or not PixelGetColor(1819, 767) = 0xFFDE4B
MouseCLick ( "primary", 1579, 546, 1, 1)
WEnd

This is clearly not working and I am confused as to how to join multiple statements using operators. The end result would be that I want to ensure that a certain button is pushed that stays visible in the background while a new window in the foreground pops up and then another pops up after that. I know of a different way to approach it that I will probably use but I still would like to know how to do it this way for my own knowledge.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'd probably do something like this.

While PixelGetColor(1579, 546) = 0xFFDE4B
    If PixelGetColor(1820, 735) <> 0xFFDE4B And  PixelGetColor(1819, 767) <> 0xFFDE4B
        Then
    MouseCLick ( "primary", 1579, 546, 1, 1)
    EndIf
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

demonachize,

When you use multiple logical operators you need to be very careful - especially if you use any Not operators in there as well. :P

Top Tip 1: Do not use multiple logical operators - split your line into 2:

While PixelGetColor(1579, 546) = 0xFFDE4B
    If PixelGetColor(1820, 735) <> 0xFFDE4B Or PixelGetColor(1819, 767) <> 0xFFDE4B Then
        MouseCLick ( "primary", 1579, 546, 1, 1)
    EndIf
WEnd

Top Tip 2: If you want to keep it on one line, then use parentheses to carefully delineate the separate sections and to define the scope of the Not operator. :x

Look at this small test script which replicates your basic logic:

; True, True, True -> True And (Not(True) Or Not(True))
;                  -> True And (False Or False)
;                  -> True And False
;                  -> False
;                  -> Exit Loop

; True, False, True -> True And (Not(False) Or Not(True))
;                   -> True And (True Or False)
;                   -> True And True
;                   -> True
;                   -> Stay in loop

; True, True, False -> True And (Not(True) Or Not(False))
;                   -> True And (False Or True)
;                   -> True And True
;                   -> True
;                   -> Stay in loop

; True, False, False -> True And (Not(False) Or Not(False))
;                    -> True And (True Or True)
;                    -> True And True
;                    -> True
;                    -> Stay in loop

; False, Any, Any -> False And (Not even evaluated)
;                 -> False
;                 -> Stay in loop
;                 -> Exit Loop

$fWanted = True
$fUnwanted_1 = True
$fUnwanted_2 = False

$iBegin = TimerInit()
While $fWanted And (Not($fUnwanted_1) Or Not($fUnwanted_2))
    If TimerDiff($iBegin) > 100 Then
        ConsoleWrite("Still In Here!" & @CRLF)
        Exit
    EndIf
    Sleep(10)
WEnd
ConsoleWrite("Out!" & @CRLF)

See how I have set the parentheses to limit the scope of the 2 Not operators and also to make sure the Or pair are always evaluated together. By changing the values of the 3 variables you can see how the While line reacts.

So I would suggest going with this for your script:

While (PixelGetColor(1579, 546) = 0xFFDE4B) And (Not (PixelGetColor(1820, 735) = 0xFFDE4B) Or Not ( PixelGetColor(1819, 767) = 0xFFDE4B))
    MouseCLick ( "primary", 1579, 546, 1, 1)
WEnd

And you might want to add a Sleep(10) as well to keep the CPU cool in a tight loop like that. :shifty:

M23

Edit: Wrong button, too soon!

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks to both of you. This makes perfect sense now. I appreciate that you took the time to give me those pointers.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0