Page 1 of 1

ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 15:37
by lkb3
What are some of the reasons that ImageSearch might throw errorLevel 2?
The help file says:
"ErrorLevel is set to ... 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option)."

I have a script that was working fine to automate tasks in a web-based product data management program, until we upgraded to the newest version this week. Now it's having all sorts of troubles. So I built a simple test script to see if I could further diagnose it:

Code: Select all

coordmode, screen
SetWorkingDir, C:\Users\%A_UserName%\Documents\TCAWS_MENUICONS\


#!c::
	ImageSearch, thisX, thisY, 0, 1920, 0, 1280, *100 "tcaws_submit_button.png"
	msgbox %errorLevel%
return
C:\Users\<username redacted>\Documents\TCAWS_MENUICONS\tcaws_submit_button.png
is right there in the correct directory, and it coninues to throw errorLevel 2.
What else should I be looking at?

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 15:39
by Xtra
Remove the quotes on the image filename. "

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 15:52
by lkb3
tried that. Doesn't make a difference. Still throws errorLevel 2

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 15:56
by andymbody
Fyi... I don't think this is correct

coordmode, screen


Try

Code: Select all

Coordmode, pixel, screen
Coordmode, mouse, screen

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 15:56
by gregster
Xtra is right. Remove the quotes around the file name.
In AHK v1, you would only add quotes to a string in a command parameter (contrary to functions), if explicitly documented (like for Run), or if you force an expression.

Fo testing, you can also try it with a full path. Also check what A_username actually returns...perhaps there is the problem.

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 16:08
by andymbody
Fix X1,Y1,X2,Y2. The coordinates you have here create a straight line from bottom towards the top of screen on far left side of screen.

ImageSearch, thisX, thisY, 0, 1920, 0, 1280


Should it be this instead?
ImageSearch, thisX, thisY, 0, 0, 1920, 1280

Re: ImageSearch errorLevel 2 question

Posted: 06 Dec 2023, 19:16
by Xtra
andymbody wrote:
06 Dec 2023, 16:08
Fix X1,Y1,X2,Y2. The coordinates you have here create a straight line from bottom towards the top of screen on far left side of screen.
That would cause :arrow: ErrorLevel = 2 for sure.