why PixelGetColor doesn't work here ? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
jsjcjsjc
Posts: 12
Joined: 25 May 2019, 03:11

why PixelGetColor doesn't work here ?

02 Oct 2019, 08:08

Here is my idea:
1.PixelGetColor the color at 724,310
2.end F8 to start my program
3.Gosub color
4.PixelGetColor the the color at 724,310 every second.
5.if the color changed, back to the main code.

But it looks my code doesn't work, is there somehing wrong ?
Thanks in advance

========================================================
....main code....
PixelGetColor,color-before,724,310,RGB
Sleep, 200
Send, {F8}
Sleep, 5000
Gosub, color
Sleep, 1000
....main code....


color:
loop
{
PixelGetColor,color-after,724,310,RGB
if (color-before = color-after)
{
sleep,1000
Continue
}
else
{
break
}
}
return
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: why PixelGetColor doesn't work here ?

02 Oct 2019, 08:40

try using "color_before" and "color_after"
User avatar
boiler
Posts: 3455
Joined: 21 Dec 2014, 02:44

Re: why PixelGetColor doesn't work here ?

02 Oct 2019, 08:46

It works if you make them valid variable names (dashes are not allowed but underscores are). Also make sure you set CoordMode as necessary.

By the way, you may want to make use of while and until in your loops rather than making the equivalent of them with if/else/break. The following is equivalent to yours (well, mostly equivalent; it does sleep whether the condition is true or not, but that can be accounted for):

Code: Select all

loop
{
	PixelGetColor,color_after,724,310,RGB
	sleep,1000
} until color_before != color_after
Edit: Just saw @John's post. The other information may be useful.
jsjcjsjc
Posts: 12
Joined: 25 May 2019, 03:11

Re: why PixelGetColor doesn't work here ?

03 Oct 2019, 07:55

John wrote:
02 Oct 2019, 08:40
try using "color_before" and "color_after"
Thank you so much, Now it is OK ;-)
jsjcjsjc
Posts: 12
Joined: 25 May 2019, 03:11

Re: why PixelGetColor doesn't work here ?

03 Oct 2019, 07:57

boiler wrote:
02 Oct 2019, 08:46
It works if you make them valid variable names (dashes are not allowed but underscores are). Also make sure you set CoordMode as necessary.

By the way, you may want to make use of while and until in your loops rather than making the equivalent of them with if/else/break. The following is equivalent to yours (well, mostly equivalent; it does sleep whether the condition is true or not, but that can be accounted for):

Code: Select all

loop
{
	PixelGetColor,color_after,724,310,RGB
	sleep,1000
} until color_before != color_after
Edit: Just saw @John's post. The other information may be useful.
Thank you so mcuh, Now it is great working :D
jsjcjsjc
Posts: 12
Joined: 25 May 2019, 03:11

Re: why PixelGetColor doesn't work here ?

04 Oct 2019, 07:47

Dear @boiler
Thank you so much for your kind help, but I got another problem.
this code in first loop is very good, It will display the clolor difference in first loop.
but in the next loops, it will display the clolor difference every 2 second nomatter the color changed or not.

here is my code.

Code: Select all

loop
	{
	PixelGetColor,color_before,724,310,RGB
	Sleep, 2000
	Gosub, color
	MsgBox, color_before= %color_before%. color_after= %color_after%
	}


color:
	{
		loop
		{
				PixelGetColor,color_after,724,310,RGB
				if (color_before = color_after)
			{
				sleep,1000
				Continue
			}
				else
			{
				break
			}
		}
	}
return
User avatar
boiler
Posts: 3455
Joined: 21 Dec 2014, 02:44

Re: why PixelGetColor doesn't work here ?

04 Oct 2019, 08:08

I don't understand what your question is. The second loop doesn't display colors, it just loops until the colors are different and returns to the first loop, which then displays the colors. Do you want it to display the colors every 2 seconds whether they have changed or not?
jsjcjsjc
Posts: 12
Joined: 25 May 2019, 03:11

Re: why PixelGetColor doesn't work here ?

05 Oct 2019, 06:29

boiler wrote:
04 Oct 2019, 08:08
I don't understand what your question is. The second loop doesn't display colors, it just loops until the colors are different and returns to the first loop, which then displays the colors. Do you want it to display the colors every 2 seconds whether they have changed or not?

Code: Select all

loop
{
	PixelGetColor,color_before,646,362,RGB
	Sleep, 2000
		loop
		{
			PixelGetColor,color_after,646,362,RGB
			sleep,1000
		} until color_before != color_after
	MsgBox, new color is %color_after%
}
here is my code, looks better, Thanks for your help :D

But I have a question regarding this code:
if the color of 646,362 changed one time when code is runing, will this code display one time MsgBox message or it will display MsgBox message every three second ?
I thought it will display only one time MsgBox message, But I am wrong, I find it will display MsgBox message every three second.... :oops:
So I am very confused. color_before and color_after are the same in the next loop after color changing. this code should keep quiet until color change again ?

could you please help me on it ?
Thank you so much
User avatar
boiler
Posts: 3455
Joined: 21 Dec 2014, 02:44

Re: why PixelGetColor doesn't work here ?  Topic is solved

05 Oct 2019, 22:31

It's really pretty simple. Just add another loop after the first one that keeps checking the color at that pixel until it's the same as color_before again:

Code: Select all

loop
{
	; keep checking until pixel color changes then report it:
	PixelGetColor,color_before,646,362,RGB
	Sleep, 2000
	loop
	{
		PixelGetColor,color_after,646,362,RGB
		sleep,1000
	} until color_before != color_after
	MsgBox, new color is %color_after%

	; wait until color is the same again before continuing outer loop:
	loop
	{
		PixelGetColor,color_after,646,362,RGB
		sleep,1000
	} until color_before = color_after
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot] and 56 guests