Can someone tell me why it does not work?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zanusso
Posts: 19
Joined: 23 Mar 2018, 17:49

Can someone tell me why it does not work?

Post by zanusso » 30 Mar 2018, 10:14

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
			}
		}


Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

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

Post by Nightwolf85 » 30 Mar 2018, 11:35

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
			}
		}

zanusso
Posts: 19
Joined: 23 Mar 2018, 17:49

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

Post by zanusso » 30 Mar 2018, 13:37

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
}


Post Reply

Return to “Ask for Help (v1)”