Jump to content

Quick question about variables, loops, and PixelGetColor...


Recommended Posts

I'm a hobbyist AutoIt user and I like to write little scripts to automate tasks for myself but I've come across something that I can't quite work out.

I've got a script that I need to monitor a certain icon and loop until it changes from one (or more) colors to any other undefinded color. I'm having trouble on how to define either the variable or the While's expression.

The script uses the PixelGetColor to get the decimal value of the icon. This is stored in variable $deccolor. I then convert that to hex and store that in $color. I have my constants set (which is where I may be going wrong) as such: $green = "[insert hex value]" and in my While expression I just used While $color = $green but even if $color is equal to green it ends the loop and continues with the script.

I assume it is just syntax and me not doing something correctly with it but I've tried several variations and I cannot figure it out so any help would be appreciated!

Edited by JuggaloZeke
Link to comment
Share on other sites

I figured but I didn't have the script on the PC I was using at the time, so here it is...

AutoItSetOption ( "WinTitleMatchMode" , 2 )

MsgBox ( 0 , "Location Selector" , "Place mouse on icon and press Enter." )

Dim $location = MouseGetPos()

;MsgBox ( 0 , "DEBUG" , "Mouse x,y: " & $location [ 0 ] & ", " & $location [ 1 ] )

Dim $deccolor = PixelGetColor ( $location [ 0 ] , $location [ 1 ] )

;MsgBox ( 0 , "DEBUG" , "Decimal color: " & $deccolor )

Dim $color = Hex ( $deccolor , 6 )

Dim Const $yellow = "71620E"

Dim Const $red = "A60000"

;MsgBox ( 0 , "DEBUG" , "Hex color: " & $color )

MsgBox ( 0 , "Ready to Start" , "The program is now ready to run." )

While 1
    
    WinActivate ( "Prog1" )
    
;   ToolTip ( "Activated Prog1." , 0 , 0 )
    
    Sleep ( 1000 )
    
    Send ( "{ENTER}" )
    
;   ToolTip ( "Sent ENTER key to connect." , 0 , 0 )
    
    Sleep ( 1000 )
    
    While $color = $yellow
        
;       ToolTip ( "Starting WHILE loop" , 0 , 0 )
    
        Sleep ( 1000 )
        
        $deccolor = PixelGetColor ( $location [ 0 ] , $location [ 1 ] )
        
;       ToolTip ( "Updating COLOR variable." , 0 , 0 )
    
        Sleep ( 1000 )
        
    WEnd
    
;   ToolTip ( "Successfully worked through first WHILE loop." , 0 , 0 )
    
    Sleep ( 1000 )
    
    WinActivate ( "Prog2" )
    
    Send ( "Test" )
    
    Sleep ( 2500 )
    
    WinActivate ( "Prog1" )
    
    Send ( "{ENTER}" )
    
    While $color = $red
    
        $deccolor = PixelGetColor ( $location [ 0 ] , $location [ 1 ] )
    
    WEnd
    
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...