Jump to content

Recommended Posts

Posted (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 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
Posted (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 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
Posted

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.

Posted (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)
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
Posted (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 by AchterlijkeVleugel
Posted (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
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
Posted

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

Posted

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

 

Posted

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 ?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...