Sign in to follow this  
Followers 0
Dag

how to set up time to execute function?

10 posts in this topic

hello

maybe someone can give me a tip , function name in help file or a sample

i try to explain my problem:

in my script i have a loop, and i need to run some other functions every 5min and other every 2h

thanks for help

and sorry for my english :F

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

if u somehow know how long the script needs to pass the loop once you can do it like this:

lets assume the script needs 1 second to pass the loop

$i = 0
While true
If Mod($i, 60) = 0 Then 
    ;this part is done every minute
EndIf
If Mod($i, 60*60*2) = 0 Then 
    ;this part is done every 2 hours
EndIf
$i += 1
;....your other code....
WEnd

be sure to inform yourself about AdLibEnable(), too.

Edited by tmo

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

tmo, thx for reply

i can't use your method

in my script you can choose some parameters, and depand of your choose script need 1s to 10s to pass the loop :P

so if i use your solution , my script call function every min 2h, max 20h if i'm correct

anyway, i need some countdown or something like that

Edited by Dag

Share this post


Link to post
Share on other sites

so you should decide to use AdLibEnable()

Share this post


Link to post
Share on other sites

a already test AdlibEnable and it seems work fine

thx for help

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

after further tests i found that i can use this function once

only last AdlibEnable work, so if i use 4 AdlibEnable to call 4 diferent functions, only last one work

here is an example of mu code

if $aaa = 1 then
AdlibEnable ( "bbb" , 20000)
endif
if $ccc = 1 then
AdlibEnable ( "ddd" , 30000)
endif
if $eee = 1 then
AdlibEnable ( "fff" , 40000)
if $ggg = 1 then
AdlibEnable ( "hhh" , 10000)
EndIf

endif

    While (1)

        MouseDown ("Right")
        Call ("refocus")
        MouseUp ("Right")
        Send (" ")
        Sleep ($speed)

    WEnd
Edited by Dag

Share this post


Link to post
Share on other sites

now think about my first method once again. what about having global variable $i which increases each time the adlib-function is called. then you can use the Mod($i, x) method again.

Share this post


Link to post
Share on other sites

now think about my first method once again. what about having global variable $i which increases each time the adlib-function is called. then you can use the Mod($i, x) method again.

or you can just have one adlib function that calls 4 other functions as necessary based on global variables... there are alot of ways to do what you want... I think i would go with TimerStart() and TimerDiff(). you can start a timer for each of the optional durations, and have TimerDiff compared for each at necessarily variable increments, and you won't need to worry about adblibs or seperate functions at all.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

or you can just have one adlib function that calls 4 other functions as necessary based on global variables... there are alot of ways to do what you want... I think i would go with TimerStart() and TimerDiff(). you can start a timer for each of the optional durations, and have TimerDiff compared for each at necessarily variable increments, and you won't need to worry about adblibs or seperate functions at all.

I was just about to recommend the TimerDiff() function myself! from the helpfile, this example...

CODE
$begin = TimerInit()

sleep(3000)

$dif = TimerDiff($begin)

MsgBox(0,"Time Difference",$dif)

Share this post


Link to post
Share on other sites

You didn't post the full script, but this is how you should probably do it:

Dim $i_TimeStamp1 = TimerInit()
Dim $i_TimeStamp2 = TimerInit()
Dim $i_TimeStamp3 = TimerInit()
Dim $i_TimeStamp4 = TimerInit()

While 1
    MouseDown ("Right")
    Call ("refocus")
    MouseUp ("Right")
    Send (" ")
    Sleep ($speed)
    IF TimerDiff($i_TimeStamp1)/1000 >= 20000 Then
        bbb()
        $i_TimeStamp1 = TimerInit()
    EndIf
    IF TimerDiff($i_TimeStamp2)/1000 >= 30000 Then
        ddd()
        $i_TimeStamp2 = TimerInit()
    Endif
    If TimerDiff($i_TimeStamp3)/1000 >= 40000 Then
        fff()
        $i_TimeStamp3 TimerInit()
    EndIf
    If TimerDiff($i_TimeStamp4)/1000 >= 10000 Then
        hhh()
        $i_TimeStamp4 = TimerInit()
    EndIf
WEnd

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
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
Sign in to follow this  
Followers 0