AchterlijkeVleugel Posted July 23, 2015 Share Posted July 23, 2015 (edited) Im trying to do a function every x minutes as a part of a whole loop script.The function is not defined in the main loop script but included from somewhere else.I'm having trouble understand the help file for the AdlibRegister function.Do you have to add adlibregister where you define the function, or do you likeAdlibregister ("Sleep")To sleep every 250 msIs unregistering adlib also mandatory? Thank you in advance! Example of what im trying to do, and how i think adlibregister works:#include ("Whatever.au3") While 1 Example () ;;The function i want to loop Adlibregister ("Whatever"[,time=10000]) ;;Do Whatever every 10 seconds Wend Edited July 23, 2015 by AchterlijkeVleugel Link to comment Share on other sites More sharing options...
mikell Posted July 23, 2015 Share Posted July 23, 2015 Adlibregister ("Whatever"[,time=10000]) ;;Run function named Whatever() every 10 seconds AchterlijkeVleugel 1 Link to comment Share on other sites More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 Adlibregister ("Whatever"[,time=10000]) ;;Run function named Whatever() every 10 secondsTerminology But would that be correct? Or would i have to add adlibregister outside the loop Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 23, 2015 Share Posted July 23, 2015 You only need to state your Adlibregister one time, so do it before your loop at the start of your script. It will repeat over and over at the set time until the script ends or you use the Unregister function. AchterlijkeVleugel 1 Link to comment Share on other sites More sharing options...
JohnOne Posted July 23, 2015 Share Posted July 23, 2015 AdlibRegister("Function", 1000) While Sleep(30) WEnd Func Function() ConsoleWrite("Called :" & @SEC & @LF) 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 More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) You only need to state your Adlibregister one time, so do it before your loop at the start of your script. It will repeat over and over at the set time until the script ends or you use the Unregister function.How would i halt the loop for the adlib function?What function would be handy for thisMaybe Global $example = 0 Then add Global $Example =+ 1 to the whatever functionThen add at the end of whatever function $Example =-1 Then check in the loop if example is 1 Edited July 23, 2015 by AchterlijkeVleugel Link to comment Share on other sites More sharing options...
JohnOne Posted July 23, 2015 Share Posted July 23, 2015 AdlibRegister("Function", 1000) While Sleep(30) WEnd Func Function() ConsoleWrite("Called :" & @SEC & @LF) If @SEC = 12 Then AdlibUnRegister("Function") EndIf 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 More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 AdlibRegister("Function", 1000) While Sleep(30) WEnd Func Function() ConsoleWrite("Called :" & @SEC & @LF) If @SEC = 12 Then AdlibUnRegister("Function") EndIf EndFunc Wouldn't that stop calling Function every second? After Sec = 12? Link to comment Share on other sites More sharing options...
SadBunny Posted July 23, 2015 Share Posted July 23, 2015 It unregisters the Adlib as soon as you hit a @SEC equal to 12. The adlib will no longer be registered, meaning it is no longer the case that Function() is called every 1000 msec. Re-enabling the adlib would require another AdlibRegister. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JohnOne Posted July 23, 2015 Share Posted July 23, 2015 Yes.How would i halt the loop for the adlib function? 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 More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) Oh i guess i didn't formulate my request properly.Adlibregister ("Function",1000) While 1 Sleep (200) Example () Wend Func Example () ($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) Endfunc Func Function () Consolewrite("Called:"&@Sec) EndfuncWhat im trying to do is, for example. Pause the While loop, when Function starts. i was thinking offGlobal $example = 0 Then add Global $Example =+ 1 to the example functionThen add at the end of example function $Example =-1Then check in the loop if $example is 1 But this would be devious, and unreliable. Edited July 23, 2015 by AchterlijkeVleugel Link to comment Share on other sites More sharing options...
JohnOne Posted July 23, 2015 Share Posted July 23, 2015 You cannot pause a while loop, you can write code in it, in such a fashion that it will not do anything, but you cannot pause it. 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 More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) You cannot pause a while loop, you can write code in it, in such a fashion that it will not do anything, but you cannot pause it.is there any function that checks if a function is active/executed? If not, how would i go about looping a script for X minutes. Edited July 23, 2015 by AchterlijkeVleugel Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 23, 2015 Share Posted July 23, 2015 (edited) Exit After X Time.I use Adlibregister() for that. I think I have seen a lot of cases where TimerInit() is used.Example:Adlibregister("Terminate", 180000) Func Terminate() Exit EndFuncIf you're just trying to exit the loop not the script that is where TimerInit() TimerDiff() come in handy so you can check the time and after X Time ExitLoopExample:$vTimer = TimerInit() While 1 Sleep(500) ConsoleWrite("Loop Running" & @CRLF) If TimerDiff($vTimer) > 3000 Then ExitLoop WEnd MsgBox(0, "", "Loop Was Exited. Resume Script") Edited July 23, 2015 by ViciousXUSMC AchterlijkeVleugel 1 Link to comment Share on other sites More sharing options...
AchterlijkeVleugel Posted July 23, 2015 Author Share Posted July 23, 2015 Exit After X Time.I use Adlibregister() for that. I think I have seen a lot of cases where TimerInit() is used.Example:Adlibregister("Terminate", 180000) Func Terminate() Exit EndFuncIf you're just trying to exit the loop not the script that is where TimerInit() TimerDiff() come in handy so you can check the time and after X Time ExitLoopExample:$vTimer = TimerInit() While 1 Sleep(500) ConsoleWrite("Loop Running" & @CRLF) If TimerDiff($vTimer) > 3000 Then ExitLoop WEnd MsgBox(0, "", "Loop Was Exited. Resume Script") Ty, i can probably get along from here myself Link to comment Share on other sites More sharing options...
mikell Posted July 23, 2015 Share Posted July 23, 2015 What im trying to do is, for example. Pause the While loop, when Function starts.Global $example = 0 Then add Global $Example =+ 1 to the example functionThen add at the end of example function $Example =-1Then check in the loop if $example is 1 But this would be devious, and unreliable. It is reliable In the pseudocode below the func Example() will not run if the func Function() is launchedGlobal $running = 0 Adlibregister ("Function",1000) While 1 Sleep (200) If $running = 1 Then ContinueLoop Example() Wend Func Example() ; do something Endfunc Func Function() $running = 1 ; do something $running = 0 Endfunc Link to comment Share on other sites More sharing options...
AchterlijkeVleugel Posted July 25, 2015 Author Share Posted July 25, 2015 It is reliable In the pseudocode below the func Example() will not run if the func Function() is launchedGlobal $running = 0 Adlibregister ("Function",1000) While 1 Sleep (200) If $running = 1 Then ContinueLoop Example() Wend Func Example() ; do something Endfunc Func Function() $running = 1 ; do something $running = 0 Endfunc Shouldn't that be if $running = 0 ? 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