Page 1 of 1

Can someone tell me why it does not work?

Posted: 30 Mar 2018, 10:14
by zanusso
Can someone tell me why this code is not working?

Code: Select all


!u::	
Gui Submit, NoHide
		Loop
		{	
			if ((PixelSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x15B96E) = true)
			;If ErrorLevel = 0
			{
				MsgBox, 1
				SoundBeep, 750, 500
				sleep 200
				Send, {end}
				Click, %OutputVarX%, %OutputVarY%
				sleep 1500
			}
		}


Re: Can someone tell me why it does not work?

Posted: 30 Mar 2018, 11:35
by Nightwolf85
PixelSearch is a command, it sets OutputVarX and OutputVarY, it doesn't return a value at all. Because of this, the check against the value true is invalid.

You could try something like this instead (not tested):

Code: Select all

!u::	
Gui Submit, NoHide
		Loop
		{	
			PixelSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x15B96E
			if (OutputVarX != "" AND OutputVarY != "")
			{
				MsgBox, 1
				SoundBeep, 750, 500
				sleep 200
				Send, {end}
				Click, %OutputVarX%, %OutputVarY%
				sleep 1500
			}
		}
Or just do what looks like was originally the code to begin with, using ErrorLevel. Check the docs page for the description about how if there is a match found ErrorLevel will be set to 0

Code: Select all

!u::	
Gui Submit, NoHide
		Loop
		{	
			PixelSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x15B96E
			If (ErrorLevel = 0)
			{
				MsgBox, 1
				SoundBeep, 750, 500
				sleep 200
				Send, {end}
				Click, %OutputVarX%, %OutputVarY%
				sleep 1500
			}
		}

Re: Can someone tell me why it does not work?

Posted: 30 Mar 2018, 13:37
by zanusso
Nightwolf85 wrote:PixelSearch is a command, it sets OutputVarX and OutputVarY, it doesn't return a value at all. Because of this, the check against the value true is invalid.

You could try something like this instead (not tested):

Code: Select all

!u::	
Gui Submit, NoHide
		Loop
		{	
			PixelSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x15B96E
			if (OutputVarX != "" AND OutputVarY != "")
			{
				MsgBox, 1
				SoundBeep, 750, 500
				sleep 200
				Send, {end}
				Click, %OutputVarX%, %OutputVarY%
				sleep 1500
			}
		}
Or just do what looks like was originally the code to begin with, using ErrorLevel. Check the docs page for the description about how if there is a match found ErrorLevel will be set to 0

Code: Select all

!u::	
Gui Submit, NoHide
		Loop
		{	
			PixelSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x15B96E
			If (ErrorLevel = 0)
			{
				MsgBox, 1
				SoundBeep, 750, 500
				sleep 200
				Send, {end}
				Click, %OutputVarX%, %OutputVarY%
				sleep 1500
			}
		}

Code: Select all



the first script worked, but I wish it were like this:

example: while or if (color exists on screen)
{
do something

}
else
{
return
}