Jump to content

Repeating Certain Steps in a Function


Recommended Posts

#include
HotKeySet("{PAUSE}", "checkForImage")
HotKeySet("{DEL}", "Terminate")
global $y = 0, $x = 0
Func checkForImage()
while 1
mousemove(960,600,10)
Local $search = _ImageSearch('FEM.bmp', 1, $x, $y, 0)
I f $search = 1 Then
MouseMove($x, $y, 10)
sleep(2000)
EndIf

wend
EndFunc
while 1
sleep(200)
WEnd
Func Terminate()
while 1
sleep(200)
wend
EndFunc

I want to add to this code and make it so that If $search returns 0 it continually searches for the image every 33ms for the next 2 seconds (time of the sleep after image is found) without having to repeat the code 60 times. Any help is much appreciated

I looked into using TimerInit and TimmerDiff but couldn't get it to act quite as i wanted.

Edited by silly135
Link to comment
Share on other sites

Here's what usually happens.

People give a user suggestions and the user says "I already tried that", peoples time is wasted.

So to avoid this, and as you are the one needing it, use your time to post everything you have tried so far.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

What I tried in the while loop:

while 1
...
$begin = TimerInit()
While 1
$dif = TimerDiff($begin)
if $dif>2000 then exitloop
Local $search = _Imagesearch('FEM.bmp',1,$x,$y,0)
If $search =1 then exitloop
wend
wend

The program doesn't give me an error, but it also doesn't run. When I check my task bar and task manager it isn't there.

Edited by silly135
Link to comment
Share on other sites

#include
HotKeySet("{PAUSE}", "checkForImage")
HotKeySet("{DEL}", "Terminate")

// script starts here, you need to keep it alive else it will just exit.
global $y = 0, $x = 0

whilw 1
sleep(100)
wend

Func checkForImage()
while 1
mousemove(960,600,10)
Local $search = _ImageSearch('FEM.bmp', 1, $x, $y, 0)
I f $search = 1 Then
MouseMove($x, $y, 10)
sleep(2000)
EndIf

wend
EndFunc
while 1
sleep(200)
WEnd
Func Terminate()
while 1
sleep(200)
wend
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...