Repeat Imagesearch

03/05/2018 21:00 Hirnverbrannt#1
Hello,

im pretty new to coding.
i tried to create a script which should do the following steps:

1. search for image
2. if it appears right click on it
3. if it doesnt appear do some mouse clicks
4. search for image again
5. if it appears right click on it
6 if it doesnt appear do some mouse clicks
and so on and so on

my result is:
without the else part the script is fine and it would right click on the image if it appears, however when i added the else part it wouldnt click on the image anymore if it appeared. (i think i use the else function wrong but let me know what you guys think)



03/06/2018 16:41 Moneypulation#2
Try using WaitForImageSearch instead and see if that solves your problem
03/06/2018 17:34 Hirnverbrannt#3
thanks for the help but that didnt work :(
03/06/2018 17:37 Moneypulation#4
Give it more shade-variation maybe
03/06/2018 18:33 Hirnverbrannt#5
i found the mistake. the picture wasnt good somehow and i had to remake it x.x
09/10/2018 20:56 VitorCornelius#6
Quote:
Originally Posted by Hirnverbrannt View Post
Hello,

im pretty new to coding.
i tried to create a script which should do the following steps:

1. search for image
2. if it appears right click on it
3. if it doesnt appear do some mouse clicks
4. search for image again
5. if it appears right click on it
6 if it doesnt appear do some mouse clicks
and so on and so on

my result is:
without the else part the script is fine and it would right click on the image if it appears, however when i added the else part it wouldnt click on the image anymore if it appeared. (i think i use the else function wrong but let me know what you guys think)



Try to avoide unnessesery orders:
move this line outsed of the While loop, since u do not have to reload the file over and over again.
$file = @DesktopDir & '\Coronet.bmp'

the sleep functions not realy needed between clicks, you can set a click speed in mouseclick("button", $x, $y, number of clicks, speed) "speed [optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10."

As Moneypulation said, use higher tolerance in imagesearch. Something like 50 or 100. value 0 mean find the exactly same image as your image stored in the file.
09/26/2018 07:25 FasTZiinnN#7
Just alternative

#include <ImageSearch.au3>

HotKeySet("s", "Start")
HotKeySet("e", "_Exit")

;Global $y = 0, $x = 0; dont need Global, you will use in same script :)
Local $y = 0, $x = 0, $Time_Out = 0
Local $Patch = @DesktopDir & '\Coronet.bmp'

Func Start()
While 1
sleep (100)

Do
Sleep(80)
$Time_Out += 1
Until _ImageSearch($Patch, 1, $x, $y, 0) = 1 Or $Time_Out = 10

If $Time_Out >= 10 Then
MouseClick ("left", 929, 691, 200)
MouseClick ("left", 960, 459, 200)
MouseClick ("left", 960, 359, 500)
Else
MouseClick("right", $X, $Y, 50)
EndIf
Wend
EndFunc

Func _Exit()
Exit()
EndFunc

While 1
Sleep(35)
WEnd
10/28/2018 19:43 Goliard2k6#8
#RequireAdmin
#include <ImageSearch.au3>

HotKeySet("s", "Start")
HotKeySet("e", "_Exit")

$y = 0, $x = 0

While 1
sleep (100)
$result = _WaitForImageSearch("Coronet.bmp",15,1,$x1,$y1,0)
if $result=1 Then

MouseClick("right", $X, $Y)
Sleep (50)
Else
MouseClick ("left", 929, 691)
Sleep (200)
MouseClick ("left", 960, 459)
Sleep (200)
MouseClick ("left", 960, 359)
Sleep (500)
EndIf
Wend




Func _Exit()
Exit
EndFunc

While 1
Sleep(100)
WEnd


PROBIER DAS MAL