Jump to content

Help w/ Adlibregister


Recommended Posts

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 like

Adlibregister ("Sleep")

To sleep every 250 ms

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

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 this

Maybe Global $example = 0 

Then add Global $Example =+ 1 to the whatever function

Then add at the end of whatever function $Example =-1

 

Then check in the loop if example is 1 

Edited by AchterlijkeVleugel
Link to comment
Share on other sites

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

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

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)
Endfunc

What im trying to do is, for example. Pause the While loop, when Function starts.

 

i was thinking off

Global $example = 0 

Then add Global $Example =+ 1 to the example function

Then add at the end of example function $Example =-1

Then check in the loop if $example is 1 

 

But this would be devious, and unreliable. 

Edited by AchterlijkeVleugel
Link to comment
Share on other sites

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

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
EndFunc

If 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 ExitLoop

Example:

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

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
EndFunc

If 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 ExitLoop

Example:

$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

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 function

Then add at the end of example function $Example =-1

Then 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 launched

Global $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

It is reliable   :)
In the pseudocode below the func Example() will not run if the func Function() is launched

Global $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

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