Sign in to follow this  
Followers 0
mwpeck

Set Timer to specified time?

4 posts in this topic

Basically, I am using a timer to time certain events in my script, the way I am using it is like:

$timer = TimerInit()
$timer2 = TimerInit()

while 1
    If TimerDiff($timer) > 5000 Then
        execute code
        $timer = TimerInit()
    ElseIf TimerDiff($timer2) > 3000 Then
        execute different code
        $timer2 = TimerInit()
    Else
        do nothing
    EndIf
WEnd

Ok, that would, hold of doing an the first or second event, until the script has bee running for 3 and 5 seconds.

Now, if I want the script to run both sections of code when it is ran, as opposed to pausing (or doing nothing) for the first 3 seconds, how can I modify $timer and $timer2 outside of the loop so it will run.

Basically, right now, the script would run for 3 seconds, hit the ElseIf, then 2 seconds later, hit the If. I want it to hit the If as soon as the code runs, then the next loop iteration, it hits the ElseIf, then after that is done, it waits 3 seconds before evaluating as true on the ElseIf and another 2 seconds before the If.

So is there any way to set the current time of a timer so I can get the script to run instantly instead of waiting until the timers tick up that high? I have looked at _Timer_SetTimer, but that seems like its just for running a certain event on a certain time, not running a timer to see when a certain command should be executed.

Share this post


Link to post
Share on other sites



Maybe...

$timer = "1stRun"
$timer2 = "1stRun"

While 1
    If $timer = "1stRun" Or TimerDiff($timer) > 5000 Then
        ConsoleWrite("Execute #1" & @CRLF)
        $timer = TimerInit()
    ElseIf $timer2 = "1stRun" Or TimerDiff($timer2) > 3000 Then
        ConsoleWrite("Execute #2" & @CRLF)
        $timer2 = TimerInit()
    Else
        ;do nothing
    EndIf
    Sleep(10) ; slow CPU useage
WEnd

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I'm totally lost in what you said. Maybe it's my head cold.

execute code
        execute different code
        sleep(300)
        check different code
        sleep(200)
        check code

That sounds like what your talking about but I doubt that's right.

Right now I need

If processexist(youknowwho) then Sleep(3000000)

Giggity

Share this post


Link to post
Share on other sites

Maybe...

<snip>

8)

Thanks, worked perfectly, wasnt sure if that was the way to do it or if you could use the variable as a timer the entire time and just set it to a specified time.

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