Page 1 of 1

pixelsearch else doesnt work

Posted: 08 Sep 2017, 06:42
by ravena1
i try to combine pixel search and imagesearch , then f5 if it theres no color and image

but only pixelsearch works and it skips imagesearch why?



Code: Select all

home::
Loop 
{
	PixelSearch, X, Y, 29, 198, 771, 577, 0x00FF00, 0, fast
	
		if(ErrorLevel=0) {
                MouseClick, left, %X%, %Y%						                 	
		}

       else 
		
		{
			
		ImageSearch,X2, Y2, 235, 43, 771, 577, C:\image\green.png
		if(ErrorLevel=0) {
                 MouseClick, left, X2, Y2

		}
     else 
                       ;--- press f5 to refresh if theres no color or image in screen
			Send {F5}
			sleep, 2500

		}
	}
return



Re: pixelsearch else doesnt work

Posted: 08 Sep 2017, 06:48
by mast4rwang
First thing I noticed you have two "else" in one bracket pair (it messes your script). Also, what I do in scripts with many conditions, I make only "IF" conditions: if it doesn't comply - it skips to another "IF". You will just make your script more complicated with many ifs and else.

Also I may be wrong, but when I was testing pixelsearch I think ErrorLevel was inversed. In one of my tests I had to use ErrorLevel instead of !ErrorLevel to make it work as intended ^^

Re: pixelsearch else doesnt work

Posted: 08 Sep 2017, 07:02
by ravena1
edit: i tried to switch else of imagesearch and pixelsearch .. make the imasearch priority
and then imagesearch worked but pixelsearch wont work, what sorcery is this?

Re: pixelsearch else doesnt work

Posted: 08 Sep 2017, 07:03
by ravena1
mast4rwang wrote:First thing I noticed you have two "else" in one bracket pair (it messes your script). Also, what I do in scripts with many conditions, I make only "IF" conditions: if it doesn't comply - it skips to another "IF". You will just make your script more complicated with many ifs and else.

Also I may be wrong, but when I was testing pixelsearch I think ErrorLevel was inversed. In one of my tests I had to use ErrorLevel instead of !ErrorLevel to make it work as intended ^^
can you make example code how to do this? im kinda newbie

Re: pixelsearch else doesnt work

Posted: 08 Sep 2017, 08:25
by WalkerOfTheDay
Does this work ?

Code: Select all

home::
Loop
{
	PixelSearch, X, Y, 29, 198, 771, 577, 0x00FF00, 0, fast
	if ErrorLevel = 0 
	{
		MouseClick, left, %X%, %Y%	
		
	}
	else 
	{
		MsgBox, PixelSearch unsuccesfull !
		ImageSearch,X2, Y2, 235, 43, 771, 577, C:\image\green.png
		if ErrorLevel = 0 
		{
			MouseClick, left, X2, Y2
		}
		else
		{
			MsgBox, Image not found !
			Send {F5}
			sleep, 2500
		}
	}
}
return
Please note, this is an infinite loop, do you ever want to break out of it when
certain conditions are met ?

Re: pixelsearch else doesnt work

Posted: 08 Sep 2017, 08:30
by Delta Pythagorean

Code: Select all

Home::
Loop {
	PixelSearch, X, Y, 29, 198, 771, 577, 0x00FF00, 0, Fast
	If (!ErrorLevel)
		MouseClick, left, %X%, %Y%	
	Else {
		MsgBox, PixelSearch unsuccesfull!
		ImageSearch, X2, Y2, 235, 43, 771, 577, C:\image\green.png
		If (!ErrorLevel)
			MouseClick, left, X2, Y2
		Else {
			MsgBox, Image not found!
			Send {F5}
			Sleep, 2500
		}
	}
}
Return
Sorry, I have a habit of shortening and cleaning up code... Heh