Sign in to follow this  
Followers 0
JuggaloZeke

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

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I guess what is happening is that the the $color is not stored as a string (?) and that is what I am creating with my constants and thus why it isn't working properly.

Share this post


Link to post
Share on other sites

Bump

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