Jump to content

how do i call a function after 10 minutes goes by


vladedoty
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 by vladedoty
Link to comment
Share on other sites

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 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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

I 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]
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 by vladedoty
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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