Jump to content

Get this to loop for 1 hour


Recommended Posts

How would I get this WHOLE thing to loop for one hour??

;delay start
Opt("MouseClickDelay", 60000 +R4())
;delay end
Dim $x1, $y1, $x2, $y2

func R4()
$t=int(Random (  1000,5000 )); pick 1000-5k
If Random() < 1000 Then $t = $t*(-1); make it neg 50%
return $t; give it back
endfunc

$x1 = 81
$y1 = 593
$x2 = 87
$y2 = 452
$speed = 5

MouseClickDrag("Left", ($x1 +R5()), ($y1 +R5()), ($x2 +R5()), ($y2 +R5()), ($speed +R5()))
; I add the number that gets returned by R5(), when it is negative, adding a negative number is the same as subtracting.

func R5()
$r=int(Random ( 1,6 )); pick 1,2,3,4,or 5
If Random() < 0.5 Then  $r = $r*(-1); 50% of the time make it negative
return $r; give the number back
endfunc
Link to comment
Share on other sites

Get the current time, and compare that time to the time until it's been one hour.

Help file, keywords, While....WEnd.

If you don't understand that, I'm sure someone will post more coherent source:

$i = 1
While $i < 5
  MsgBox("","","Loop!")
  $i = $i +1 
WEnd

The previous source should loop 6 times (going from 1, 2, 3, 4, 5, 6) in which 6 is greater than 5, so the while statement is now false and stops repeating.

Simply apply that concept to your script.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Put it inside the While statement, just like your funcs.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Try, it should work if the whole loop is shorter than a hour.

Dim $X1, $Y1, $X2, $Y2, $H, $M
$H = @HOUR
$M = @MIN
;Calculate the 'next hour'
If $H < 23 Then
   $H = $H + 1
Else
   $H = 0
EndIf

Do;<--- The loop begin.
  ;delay start
   Opt ("MouseClickDelay", 60000 + R4())
  ;delay end
   
   $X1 = 81
   $Y1 = 593
   $X2 = 87
   $Y2 = 452
   $SPEED = 5
   
   MouseClickDrag("Left", ($X1 + R5()) , ($Y1 + R5()) , ($X2 + R5()) , ($Y2 + R5()) , _
   ($SPEED + R5()))
  ; I add the number that gets returned by R5(), when it is negative, adding a
  ; negative number is the same as subtracting.
Until ($H = @HOUR And $M >= @MIN);<--- The loop stops
;                                  when the 'next hour' arrive.

Exit
Func R4()
   $T = Int(Random( 1000, 5000)); pick 1000-5k
   If Random() < 0.5 Then $T = -$T; make it neg 50%
   Return $T; give it back
EndFunc  ;==>R4

Func R5()
   $R = Int(Random(1, 6)); pick 1,2,3,4,or 5
   If Random() < 0.5 Then  $R = -$R; 50% of the time make it negative
   Return $R; give the number back
EndFunc  ;==>R5

There is no need of putting Dims inside a loop. If you need to reset your Variants set them to zero or to your needed value.

Also putting the Func all in a single place, usually in the botton or in the top of the script is much tidier. Anyway, never put their definition (Func - EndFunc part) inside a loop it is waste since they are executed only when called, not when definited.

In your case R4 is executed in

Opt ("MouseClickDelay", 60000 + R4())

and R5 in

MouseClickDrag("Left", ($X1 + R5()) , ($Y1 + R5()) , ($X2 + R5()) , ($Y2 + R5()) , _

($SPEED + R5()))

Do you see?

Hope it helps! :)

Edited by ezzetabi
Link to comment
Share on other sites

I think I would use the timer actually, because I hate to account for things like 4:59 pm

Hour <> hour in 1 minute, and things like midnight, etc etc.

I like ezzetabi's solution, but if you started at 4:59, @min would never be >$m and if the loop took over 60 sec, it might not be equal as well. Especially with a 60 sec delay in it. Almost every other situation was covered though.

anyway here is the change.

Dim $X1, $Y1, $X2, $Y2, $H, $M
$begin = TimerInit(); this starts the timer

Do;<--- The loop begin.
;delay start
  Opt ("MouseClickDelay", 60000 + R4())
;delay end
 
  $X1 = 81
  $Y1 = 593
  $X2 = 87
  $Y2 = 452
  $SPEED = 5
 
  MouseClickDrag("Left", ($X1 + R5()) , ($Y1 + R5()) , ($X2 + R5()) , ($Y2 + R5()) , _
  ($SPEED + R5()))
; I add the number that gets returned by R5(), when it is negative, adding a
; negative number is the same as subtracting.
Until ( (TimerDiff($begin)/60000)>60);<--- The loop stops
;                                  when the 'next hour' arrive.
; TimerDiff calculates time in milliseconds, so 60,000 milliseconds is 1 min
; so 60 minutes is an hour, no matter what time you start.

Exit
Func R4()
  $T = Int(Random( 1000, 5000)); pick 1000-5k
  If Random() < 0.5 Then $T = -$T; make it neg 50%
  Return $T; give it back
EndFunc;==>R4

Func R5()
  $R = Int(Random(1, 6)); pick 1,2,3,4,or 5
  If Random() < 0.5 Then  $R = -$R; 50% of the time make it negative
  Return $R; give the number back
EndFunc;==>R5
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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...