vladedoty Posted September 19, 2009 Posted September 19, 2009 How would i call a function once 10 minutes or however amount of minutes go by? I've tried the AdlibEnable function and the _Timer_SetTimer function but maybe I am not doing it correctly Any help would be much appreciated thx
Hawkwing Posted September 19, 2009 Posted September 19, 2009 Look at TimerInit and TimerDiff The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
JohnOne Posted September 19, 2009 Posted September 19, 2009 Am I being naive suggesting Sleep(6000000) ? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Hawkwing Posted September 19, 2009 Posted September 19, 2009 Am I being naive suggesting Sleep(6000000) ?Probably, I was assuming that he wanted other stuff going on during the ten minute wait before calling the function. If that's not the case though, then sleep(6000000) would work just as well. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
vladedoty Posted September 20, 2009 Author Posted September 20, 2009 (edited) Probably, I was assuming that he wanted other stuff going on during the ten minute wait before calling the function. If that's not the case though, then sleep(6000000) would work just as well. yes i definetly have other stuff going on but this is what i wrote and it doesn't call the function #include <Timers.au3> $userNumMins = 10 $totMins = $userNumMins * 6000 $begin = TimerInit() Do Sleep(100) $dif = TimerDiff($begin) Until $dif >= $totMins If $dif >= $totMins Then Start() Endif Edited September 20, 2009 by vladedoty
colafrysen Posted September 20, 2009 Posted September 20, 2009 (edited) Isn't AdlibEnable better for this purpose ?If you want to call the function several times, yes.Also, he could disable the adlib functionality inside the function if he wanted it to run just once. This way adlib is the easiest way around. Edited September 20, 2009 by colafrysen [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
SoulA Posted September 20, 2009 Posted September 20, 2009 yes i definetly have other stuff going on but this is what i wrote and it doesn't call the function #include <Timers.au3> $userNumMins = 10 $totMins = $userNumMins * 6000 $begin = TimerInit() Do Sleep(100) $dif = TimerDiff($begin) Until $dif >= $totMins If $dif >= $totMins Then Start() Endif Have you tested this code above? What does it do when you run it? The major thing I noticed is you have 6000 (6 seconds) instead of 60000 (minute) which could be throwing things off a bit.
vladedoty Posted September 20, 2009 Author Posted September 20, 2009 Have you tested this code above? What does it do when you run it? The major thing I noticed is you have 6000 (6 seconds) instead of 60000 (minute) which could be throwing things off a bit.I did try it with 60000 and no luck and I do want to just call the function once when it reaches the desired amount of minutes which is 10 in this example. Then I want it to reset so it will start the for next loop over again and reset the timer for the next 10 minutes, then call the function again. until the loop ends
colafrysen Posted September 20, 2009 Posted September 20, 2009 I did try it with 60000 and no luck and I do want to just call the function once when it reaches the desired amount of minutes which is 10 in this example. Then I want it to reset so it will start the for next loop over again and reset the timer for the next 10 minutes, then call the function again. until the loop endsI think that you should try the Aldib functions as another member suggested. They run the specified function every #### milliseconds.So you would need to use AdlibEnable("start",10*60*1000) [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Hawkwing Posted September 20, 2009 Posted September 20, 2009 This works just fine for me. $timewait = 10 $timewait *= 1000 $timer = TimerInit() While 1 ToolTip("while loop") Sleep(100) $diff = TimerDiff($timer) If $diff >= $timewait Then test() $timer = TimerInit() EndIf WEnd Func test() ToolTip("Test") Sleep(1000) EndFunc but I've never really looked at any Adlib functions, so I don't know whether or not they'd be better to use. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
vladedoty Posted September 20, 2009 Author Posted September 20, 2009 This works just fine for me. $timewait = 10 $timewait *= 1000 $timer = TimerInit() While 1 ToolTip("while loop") Sleep(100) $diff = TimerDiff($timer) If $diff >= $timewait Then test() $timer = TimerInit() EndIf WEnd Func test() ToolTip("Test") Sleep(1000) EndFunc but I've never really looked at any Adlib functions, so I don't know whether or not they'd be better to use. do I need to use a while loop to make it work or can i incorporate it just in another function. Also this does it every ten seconds correct? I'm really new and the Adlibenable help doesn't really explain what to do. Could u guys give me an example?
colafrysen Posted September 20, 2009 Posted September 20, 2009 do I need to use a while loop to make it work or can i incorporate it just in another function. Also this does it every ten seconds correct? I'm really new and the Adlibenable help doesn't really explain what to do. Could u guys give me an example? A small example: (NOTE I am using the beta, I thing its called AdlibEnable in 3.3.0.0 $SecondsToWait = 10 AdlibRegister("_Test", $SecondsToWait * 1000) While 1 Sleep(10) WEnd Func _TEST() ConsoleWrite("hello" & @CRLF) EndFunc ;==>_Test [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
vladedoty Posted September 20, 2009 Author Posted September 20, 2009 (edited) A small example: (NOTE I am using the beta, I thing its called AdlibEnable in 3.3.0.0 $SecondsToWait = 10 AdlibRegister("_Test", $SecondsToWait * 1000) While 1 Sleep(10) WEnd Func _TEST() ConsoleWrite("hello" & @CRLF) EndFunc ;==>_Test no go on the adlib function here is my function func begin() $userNumMins = 10 For $x = 0 To 2 $totMins = $userNumMins * 60000 AdlibRegister("Do", $totMins) AdlibUnRegister("Do") endfunc func Do() msgbox(0, "Message", "10 minutes has passed by") endfunc Edited September 20, 2009 by vladedoty
Hawkwing Posted September 20, 2009 Posted September 20, 2009 Well, first, you have no "next" to end your "for" loop, second, it looks to me like you unregister it right after you register it. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
vladedoty Posted September 20, 2009 Author Posted September 20, 2009 Well, first, you have no "next" to end your "for" loop, second, it looks to me like you unregister it right after you register it.there is a next in the loop i just forgot to put it in hereso when do i unregister it if i do have to?
colafrysen Posted September 20, 2009 Posted September 20, 2009 (edited) there is a next in the loop i just forgot to put it in here so when do i unregister it if i do have to? Well First. Why do you use a for next, do you really have to register your functions 3 times?, I don't think that will work... Secondly, I wouldn't use Do as a function name, as it is a loop indicator (I don't know if this actually causes any problems, but it feels wrong) Last, Unregister the adlib when you want the function to not be executed every 10 minutes, you can do this at exit (even though I think this is done automaticlly) begin() Func begin() $userNumMins = 10 ;~ For $x = 0 To 2 $totMins = $userNumMins * 60000 AdlibRegister("DoSomething", $totMins) ;~ Next EndFunc ;==>begin Func DoSomething() MsgBox(0, "Message", "10 minutes has passed by") EndFunc ;==>DoSomething Func OnAutoItExit() AdlibUnRegister("DoSomething") EndFunc ;==>OnAutoItExit Edited September 20, 2009 by colafrysen [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now