# Simple Colorget with viable problem

## Recommended Posts

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
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 on other sites

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
EndIf

##### Share on other sites

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
EndIf

##### Share on other sites

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

##### Share on other sites

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
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 on other sites

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 on other sites

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 on other sites

Ahh, ok thanks. What does the 6 denote?

In Hex(\$var, 6)

Edit: Oh nm that the viable is 6 digits.

Edited by forgetoo

## Create an account

Register a new account

×

• Wiki

• Back

• Git