depddo

[help] restarting script after a number of clicks

4 posts in this topic

Hello,

I only started learning autoit yesterday, and I have been stuck on this issue for while.

I want this script to do the following:
1) open an image gallery website (through clicks)
2) search for an image on screen, if the image is not on screen then click the next button (always in the same spot)
3) keep clicking next until finds the image.
4) once finds the image click and close window 
5) repeat

Now if the image detection is 100% I wouldn't have an issue, but sometimes it misses the picture, and I want the script to start all over if this happens... I'm not sure what the best way is, I was thinking after a certain # of clicks (which represent the pages it needs to scroll through).

Any help would be appreciated!

 

#include <image_search.au3>
HotKeySet("{ESC}", "Terminate")
While 1
_WinWaitActivate("New Tab - Google Chrome","")
MouseClick("left",1909,55,1)
MouseClick("left",1823,122,1)
MouseClick("left",1788,77,1)
MouseClick("left",1622,241,1)
_WinWaitActivate("shareimage - Google Chrome","")
MouseClick("left",590,599,1)
Sleep(1000)
search_code()
WEnd
Func Terminate()
    Exit 0
EndFunc
Func get_sample_target_sign()
    Local $sign[9]
    $sign[0] = 10128249
    $sign[1] = 1446936
    $sign[2] = 6121812
    $sign[3] = 2038550
    $sign[4] = 1769472
    $sign[5] = 986896
    $sign[6] = 3544082
    $sign[7] = 328207
    $sign[8] = 854795
    return $sign
EndFunc
func search_code()
    Sleep(2000)
    $img_pos = image_search(get_sample_target_sign(),55,42)
    if $img_pos[0] <> -1 then
        MouseClick("left",$img_pos[0]+10,$img_pos[1]+50)
        sleep(1000)
        MouseClick("left",1891,6)
    else
        MouseClick("left",1115,908)
        search_code()
    endif
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You want the script to start over or the Function?

Both answers involve setting up an error handler.

Exiting and restarting the script I would steer clear of.

Set up your script so that the function that would fail and need to be restarted can be controlled by the error handler.

For instance:

If _imgSearch = 0 Then

Exitloop

Restart Function

etc.

Edited by l3ill

Share this post


Link to post
Share on other sites
12 hours ago, depddo said:

Now if the image detection is 100% I wouldn't have an issue, but sometimes it misses the picture,

when misses it can't be 100%. Please attach the pictures (at least the pictures that are missed)

Share this post


Link to post
Share on other sites

I would add a tolerance value to img search, and test.


BeatsPlayer - My Music player

"Know what really grinds my gears? Those people who quote whole posts for no reason." Peter Griffin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now