Noob alert - Potential value type mismatch? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Waschischi2016
Posts: 3
Joined: 07 Aug 2022, 17:06

Noob alert - Potential value type mismatch?

Post by Waschischi2016 » 07 Aug 2022, 17:36

Hi all,

First of all, if this intro is TLTR, goto “now comes the part where I call the cavalry.”

A short introduction before diving into my question. This helps you maybe a bit better what and why I am trying to achieve. In my mancave i have a few walls soundproofed. Through this soundproof runs a led setup with close to 2000 LED's, making this a led wall. This led wall is controlled by an app called WLED, and set-up in a way that i can control the patterns with HTTP GET requests for (home) automation purposes.
During my gaming sessions events are happening which I want to show on the wall for a bit extra immersion. Like getting shot during gameplay in shooters, the wall flashes red, or during a race game when the yellow flag comes out, the wall is blinking yellow. During police chases, the wall is flashing red and blue, well, you get the point.
To achieve all this, I could go for an UDP config, but not all the games support this option. So, I decided to interpret the color of specific pixels on the screen. My gaming screen is always the same screen and in the middle of my three screen setup. So based on this, I can define the pixel’s x and y position.

Now comes the part where I call the cavalry:

I use the code enclosed below. I need the code recognize that specific pixel when it has color code “F0F0F0”. After that, it has to check for the switch value Z. This value is important to avoid overload the WLED server to overload in HTTP requests.
To be precise: If the pixel contains the requested value AND the control is zero, Do stuff (the position of “msgbox, Found”. Also, when the pixel contains anything but the requested value AND the zero is 1, Do other stuff (the position of “msgbox, NotFound).
How this code handles until now: with the Tooltip lines I can confirm whether at the right time the right value is found by PixelGetColor, which is working fine. But, I cannot let the code understands that it needs to do stuff based on that value. I think I mismatched something somewhere, but as a started in AHK, I cannot oversee nor find it.

Code: Select all

#SingleInstance, Force
;x:=1878
;y:=31
;x:=2698
;y:=223
z=0
x:=1878
y:=31
color2check=F0F0F0

CoordMode,Pixel,screen
ToolTip, started
Loop
{

	PixelGetColor,readpixelcolor,x,y,RGB
  	StringTrimLeft,readpixelcolor,readpixelcolor,2
	;mousemove, x,y
	If (readpixelcolor <> F0F0F0)
	{
		tooltip, %readpixelcolor% %z%
		if (z == 1)
		{
			msgbox, NotFound
			z = 0
		}
	}
	If (readpixelcolor = F0F0F0)
	{
		tooltip, %readpixelcolor% %z%
		if (z == 0)
		{
			msgbox, Found
			z = 1
		}
	}
	sleep, 100
	tooltip,
}

Numpad0::
msgbox, exit
ExitApp
Disclaimer: This is just the start of a based code, and I am trying to get the hang of it. Who is willing to be my “cavalry” and can help me out? Many thanks anyway for still reading this post, eternal fame for anyone who has the solution of a way better plan than this…

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Noob alert - Potential value type mismatch?  Topic is solved

Post by boiler » 07 Aug 2022, 17:49

F0F0F0 is seen as either a string (such as in the case where you assign it using legacy syntax as color2check=F0F0F0) or as a variable (like when you use it in an expression as If (readpixelcolor <> F0F0F0)) — neither of which is what you want. To refer to the hex value, as is returned from PixelGetColor, you need to precede it with 0x, so it would be 0xF0F0F0.

Documentation reference:
Expressions wrote:Within expressions and non-expressions alike, integers may be written in either hexadecimal or decimal format. Hexadecimal numbers all start with the prefix 0x. For example, Sleep 0xFF is equivalent to Sleep 255.

Waschischi2016
Posts: 3
Joined: 07 Aug 2022, 17:06

Re: Noob alert - Potential value type mismatch?

Post by Waschischi2016 » 07 Aug 2022, 18:06

boiler wrote:
07 Aug 2022, 17:49
F0F0F0 is seen as either a string (such as in the case where you assign it using legacy syntax as color2check=F0F0F0) or as a variable (like when you use it in an expression as If (readpixelcolor <> F0F0F0)) — neither of which is what you want. To refer to the hex value, as is returned from PixelGetColor, you need to precede it with 0x, so it would be 0xF0F0F0.
Thank you for you quick response. I really appreciate that. I change the code a bit and it seems to be working until i let it check for a second color. So, 0xF0F0F0 is the way which works, but i ran into a flashing pixel so i have to include a second color. As seen in my code below, i want the color code when AHK finds a found value different than the two i am looking for. However, the tooltip, "NotFound %readpixelcolor%" also results in a tooltip with "NotFound 0x646464". What can that be?

Code: Select all

#SingleInstance, Force
;x:=1878
;y:=31
;x:=2698
;y:=223
z=1
x:=1878
y:=31
CoordMode,Pixel,screen
ToolTip, started
Loop
{
	PixelGetColor,readpixelcolor,x,y,RGB
	If (readpixelcolor = 0xF0F0F0)
	{
		if (z == 0)
		{
			tooltip, Found
			z = 1
		}
	}
	If (readpixelcolor = 0x646464)
	{
		if (z == 0)
		{
			tooltip, Found
			z = 1
		}
	}
	If (readpixelcolor <> 0xF0F0F0)
	{
		if (z == 1)
		{
			tooltip, NotFound %readpixelcolor%
			z = 0
		}
	}
	sleep, 1000
	tooltip,
}

Numpad0::
msgbox, exit
ExitApp

[Mod edit: Fixed quote tags.]

Waschischi2016
Posts: 3
Joined: 07 Aug 2022, 17:06

Re: Noob alert - Potential value type mismatch?

Post by Waschischi2016 » 07 Aug 2022, 18:34

boiler wrote:
07 Aug 2022, 17:49
F0F0F0 is seen as either a string (such as in the case where you assign it using legacy syntax as color2check=F0F0F0) or as a variable (like when you use it in an expression as If (readpixelcolor <> F0F0F0)) — neither of which is what you want. To refer to the hex value, as is returned from PixelGetColor, you need to precede it with 0x, so it would be 0xF0F0F0.

Documentation reference:
Expressions wrote:Within expressions and non-expressions alike, integers may be written in either hexadecimal or decimal format. Hexadecimal numbers all start with the prefix 0x. For example, Sleep 0xFF is equivalent to Sleep 255.
This was a genuinely fast answer! And an answer to solve my question. To help each other out, this is my working code, fully functional HTTP requests for my case:

Code: Select all

#SingleInstance, Force
;x:=1878
;y:=31
;x:=2698
;y:=223
z=1
x:=1878
y:=31
CoordMode,Pixel,screen
ToolTip, started
Loop
{
	PixelGetColor,readpixelcolor,x,y,RGB
	If (readpixelcolor = 0xF0F0F0)
	{
		if (z == 0)
		{
			tooltip, Found
			gosub, colorfound
			z = 1
		}
	}
	else if (readpixelcolor = 0x646464)
	{
		if (z == 0)
		{
			tooltip, Found
			gosub, colorfound
			z = 1
		}
	}
	else 
	{
		if (z == 1)
		{
			tooltip, NotFound %readpixelcolor%
			gosub, colornotfound
			z = 0
		}
	}
	sleep, 100
	tooltip, %z%
}

colorfound:
HTTP:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET","http://ledwall.local/win&PL=7&tt=1")
HTTP.Send()
return

colornotfound:
HTTP:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET","http://ledwall.local/win&PL=11&tt=1")
HTTP.Send()
return

Numpad0::
msgbox, exit
ExitApp

Post Reply

Return to “Ask for Help (v1)”