Repeat Until Image Found Topic is solved

Ask gaming related questions (AHK v1.1 and older)
james_vi
Posts: 2
Joined: 18 Nov 2017, 21:15

Repeat Until Image Found

Post by james_vi » 18 Nov 2017, 22:50

Hi I want to do a script that is looking for image1 but if the image1 is not found it must click in x position until image1 is found. it is for a game that the furnace don't make me able to collect Bars until smelting sucessfully xD, obviously I can use sleep but it is most effcient save time. I will use this example in notepad:


image1=mmm (three m)
if image1 is not found write m repetedly until image1 is found.
when image1 is found write OK. I need the correct command In this case.

Code: Select all

WinActivate, Nuevo documento de texto.txt: Bloc de notas ahk_class Notepad
Sleep, 333
Loop
{
    CoordMode, Pixel, Window
    ImageSearch, FoundX, FoundY, 6, 44, 152, 70, C:\Users\JAVI\AppData\Roaming\MacroCreator\Screenshots\Screen_20171118215213.png
}
Until ErrorLevel = 0
If ErrorLevel
{
    Loop
    {
        Send, {m}
        Sleep, 10
    }
}
Sleep, 10
Send, {o}
Sleep, 93
Send, {k}

In that code the script write "m" and never stop....

My question is what is the correct loop to use in this case? a loop that stops when image1 is found either cliking or writting or whatever. Gracias de antemano

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Repeat Until Image Found  Topic is solved

Post by Xtra » 19 Nov 2017, 00:44

Try this:

Code: Select all

CoordMode, Pixel, Window

WinWait, Nuevo documento de texto.txt: Bloc de notas ahk_class Notepad
WinActivate, Nuevo documento de texto.txt: Bloc de notas ahk_class Notepad
Sleep, 333
Loop
{
    ImageSearch, FoundX, FoundY, 6, 44, 152, 70, C:\Users\JAVI\AppData\Roaming\MacroCreator\Screenshots\Screen_20171118215213.png
	if (ErrorLevel = 0)
	{
        Sleep, 10
        Send, o
        Sleep, 93
        Send, k
		break
	}
	Send, m
	Sleep, 10	
}

james_vi
Posts: 2
Joined: 18 Nov 2017, 21:15

Re: Repeat Until Image Found

Post by james_vi » 19 Nov 2017, 11:52

Oh boy your solved easily xD Thanks mate. I wish to learn more about programation and this program, I will apply the script to the game, Thanks again.

Ragnar4293
Posts: 12
Joined: 10 Oct 2021, 16:19

Re: Repeat Until Image Found

Post by Ragnar4293 » 17 Oct 2021, 23:46

How would i change this to click if not found, ignore if found, my game has 10 rows that the background is #15571d, so i would want to add 10 images with the location of rows and if the row is not #15571d click that row.

Post Reply

Return to “Gaming Help (v1)”