pixelsearch else doesnt work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

pixelsearch else doesnt work

08 Sep 2017, 06:42

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


mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: pixelsearch else doesnt work

08 Sep 2017, 06:48

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 ^^
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: pixelsearch else doesnt work

08 Sep 2017, 07:02

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?
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: pixelsearch else doesnt work

08 Sep 2017, 07:03

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
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: pixelsearch else doesnt work

08 Sep 2017, 08:25

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 ?
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: pixelsearch else doesnt work

08 Sep 2017, 08:30

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

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 372 guests