Jump to content
Sign in to follow this  
forgetoo

Simple Colorget with viable problem

Recommended Posts

forgetoo

So here is my code that I've been testing with.

$var = PixelGetColor( 1 , 1 )
MsgBox(0,"The decmial color is", $var)
MsgBox(0,"The hex color is", Hex($var, 6))

If $var == "000000" Then 
    MsgBox(0,"Color found!", Hex($var))
Else 
    MsgBox(0,"Color not found!", Hex($var))
EndIf

My screens background is black so the hex is 000000. Next it should check the first pixel on the screen and see its black it reports 0 and 000000 as hex. So I know this is correct. However the variable is not == 000000 I'm guessing for some reason because it reports the else statement and says Color not found and displays my hex of 000000. Even though it obviously finds it because it reports it correctly in the above call. So whats done wrong. I imagine it pretty simple. I'm very rusty also, so I'm guessing it might be my design of if then statements I dont know?

Share this post


Link to post
Share on other sites
ChrisFromBoston

Your if statement is still just looking at VAR, which is the RGB color (0) of the pixel. If you want to compare against the hex value, use:

$var = PixelGetColor( 1 , 1 )
MsgBox(0,"The decmial color is", $var)
MsgBox(0,"The hex color is", Hex($var, 6))

If Hex($var, 6) == "000000" Then
    MsgBox(0,"Color found!", Hex($var))
Else
    MsgBox(0,"Color not found!", Hex($var))
EndIf

Share this post


Link to post
Share on other sites
zorphnog

You are trying to compare $var (a decimal) to a hex value "000000". You need to convert $var to hex before the comparison. Try this:

$var = PixelGetColor( 1 , 1 )
MsgBox(0,"The decmial color is", $var)
MsgBox(0,"The hex color is", Hex($var, 6))

If Hex($var, 6) == "000000" Then
    MsgBox(0,"Color found!", Hex($var, 6))
Else
    MsgBox(0,"Color not found!", Hex($var, 6))
EndIf

Share this post


Link to post
Share on other sites
will88

Also, when your comparing something in AutoIt you only need one "=" unless your checking for case sensitivity then use "=="

Share this post


Link to post
Share on other sites
martin

So here is my code that I've been testing with.

$var = PixelGetColor( 1 , 1 )
 MsgBox(0,"The decmial color is", $var)
 MsgBox(0,"The hex color is", Hex($var, 6))
 
 If $var == "000000" Then 
     MsgBox(0,"Color found!", Hex($var))
 Else 
     MsgBox(0,"Color not found!", Hex($var))
 EndIf

My screens background is black so the hex is 000000. Next it should check the first pixel on the screen and see its black it reports 0 and 000000 as hex. So I know this is correct. However the variable is not == 000000 I'm guessing for some reason because it reports the else statement and says Color not found and displays my hex of 000000. Even though it obviously finds it because it reports it correctly in the above call. So whats done wrong. I imagine it pretty simple. I'm very rusty also, so I'm guessing it might be my design of if then statements I dont know?

PixelGetColor returns the number of the colour. So $var is a number and not a string. "000000" is a string so $var will not be equal to "000000" when you use == but will be if you use =.

Or try

If $var = 0 then;or If $var = 0x0
...etc

which I think is more intuitive.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
forgetoo

Thanks for these replies. I knew it was something simple. The using one equal seems to be the best option currently for what I need it to do.

Share this post


Link to post
Share on other sites
ChrisFromBoston

Thanks for these replies. I knew it was something simple. The using one equal seems to be the best option currently for what I need it to do.

Be careful, that's only working because you're using black and both RGB black and HEX black are 0. If you move to most other colors, it will not work just removing one equal sign if you're trying to compare the RGB color returned by PixelGetColor with the hex value as it would appear you're attempting to do.

Share this post


Link to post
Share on other sites
forgetoo

Ahh, ok thanks. What does the 6 denote?

In Hex($var, 6)

Edit: Oh nm that the viable is 6 digits.

Edited by forgetoo

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.