Rob Posted October 30, 2005 Share Posted October 30, 2005 I have a script that uses multiple functions. The first function is very simple bit of code that I want to be called only once every ten minutes. I don't know how to do this because when I put sleep(600000), it doesn't sleep just the that specific function for ten minutes, it pauses the entire script. Is it possible to pause one function for a certain amount of time while the rest of the script goes as normal? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 31, 2005 Moderators Share Posted October 31, 2005 (edited) Does this help or give an idea? Func One() $Timer_One = TimerInit() While 1 ;rest of my script If TimerDiff($Timer_One) >= (60000) Then ExitLoop EndIf WEnd Two() EndFunc Func Two() $Timer_Two = TimerInit() While 1 ;rest of my script If TimerDiff($Timer_Two) >= (60000) Then ExitLoop EndIf WEnd One() EndFunc Edit: I had it exiting without going to the next function and doing it if it were less than ! Edited October 31, 2005 by ronsrules Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2005 Share Posted October 31, 2005 (edited) i prefer a little more like this Dim $Timer_One One() While 1 If TimerDiff($Timer_One) >= (1000 * 60 * 10) Then One() EndIf Sleep(20) WEnd Func One() MsgBox(0,"function called", "will run again in 10 minutes ") $Timer_One = TimerInit() EndFunc then the whole script can continue @ronrules If TimerDiff($Timer_One) <= (60000) Then should be ">=" 8) Edited October 31, 2005 by Valuater Link to comment Share on other sites More sharing options...
markusss Posted October 31, 2005 Share Posted October 31, 2005 I would do this, less code: Func One() $Timer_One = TimerInit() While 1 MainProgram() If TimerDiff($Timer_One) <= (60000) Then ExitLoop EndIf WEnd Two() EndFunc Func Two() $Timer_Two = TimerInit() While 1 MainProgram() If TimerDiff($Timer_Two) <= (60000) Then ExitLoop EndIf WEnd One() EndFunc Func MainProgram() ... EndFunc But both would work the same Felix N. Link to comment Share on other sites More sharing options...
markusss Posted October 31, 2005 Share Posted October 31, 2005 (edited) Valuater, shouldn't yours be like this?: [Edit] Lol, never mind, me being dumb again Edited October 31, 2005 by Felix N. Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2005 Share Posted October 31, 2005 I would do this, less code:Func One() $Timer_One = TimerInit() While 1 MainProgram() If TimerDiff($Timer_One) <= (60000) Then ExitLoop EndIf WEnd Two() EndFunc Func Two() $Timer_Two = TimerInit() While 1 MainProgram() If TimerDiff($Timer_Two) <= (60000) Then ExitLoop EndIf WEnd One() EndFunc Func MainProgram() ... EndFuncBut both would work the sameFelix N.i dont think thats good to call more than 1 function from within functionsand the main code becomes secondary to a 10 minute wait for one function8)and">=" Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 31, 2005 Moderators Share Posted October 31, 2005 Yeh.. Val.. Thanks for noticing my short comming, I edited it before you posted Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2005 Share Posted October 31, 2005 (edited) Valuater, shouldn't yours be like this?:[Edit] Lol, never mind, me being dumb again no you took out the dim that is needed and the function is called to initiate the time right after you initiated the timeexamplehey... you moved the script..oh...ok8)editit works... the message box just poped-up with 10 minutes past8) Edited October 31, 2005 by Valuater Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 31, 2005 Moderators Share Posted October 31, 2005 Val has a good one if he's only ever using the main while. I have programs that after leaving the main GUI, then they never return to the main while again, so I coded mine so that if you should ever only use your functions then it would work just as well. I use this type of timer function often. I haven't had any leaks as long as I exit out of it and into another function. The problem if not careful is not calling the correct function to go to after words which Val's avoids. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Rob Posted October 31, 2005 Author Share Posted October 31, 2005 The if statement does not seem to work is there something else that has to be done to initialize the timer it will start the first function and run it but will not exit the loop to run the second function Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2005 Share Posted October 31, 2005 i kept that script running and every 10 minutes a message box showed up... so show us your code so we can see the error 8) Link to comment Share on other sites More sharing options...
markusss Posted October 31, 2005 Share Posted October 31, 2005 Hmm, I really don't see why this wouldn't work.... this should even work with the stable release.. Just to make it clear: Dim $Timer_One One() While 1 If TimerDiff($Timer_One) >= (1000 * 60 * 10) Then One() EndIf Sleep(20) WEnd Func One() MsgBox(0,"function called", "will run again in 10 minutes") ;<--------------------- $Timer_One = TimerInit() EndFunc You replace the MsgBox (where the arrow is) with your main code! Felix Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2005 Share Posted October 31, 2005 Hmm, I really don't see why this wouldn't work.... You replace the MsgBox (where the arrow is) with your main code!FelixI think he is having the problem with the second function....thats why i asked to see his code8) Link to comment Share on other sites More sharing options...
LxP Posted October 31, 2005 Share Posted October 31, 2005 Does AdLibEnable() suit your needs? It is used to declare that some function should be run at some repeated time interval. Link to comment Share on other sites More sharing options...
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