Sign in to follow this  
Followers 0
epicfail

make a while loop end after 10min?

29 posts in this topic

how would i have a while loop end after 10 min so after to min it sends exitloop or something?

Share this post


Link to post
Share on other sites



You're close..

1. TimerInit does not take parameters

2. You still need to replace ".. whatever value here for 10 minutes" for a return value from TimerDiff that matches 10 minutes ..

Share this post


Link to post
Share on other sites

it dosnt really say much in there 2 work with a loop

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I'll explain it. It's not really specific to the looping.

TimerDiff returns the time difference (in milliseconds) from a previous call to TimerInit().

For example we have this script:

$init = TimerInit()

While TimerDiff($init) <= 1000
    Sleep(100)
Wend

This script will make 10 loops. Why?

First loop 0ms, second loop 100ms, third loop 300ms, fourth loop 400ms. Then loop 10 = 1000ms, loop 11 = 1100ms but that's too much. 1100 <= 1000 is False.

So what you need to do now is correct your script, so that the value that the time difference must be smalelr than 10 minutes expressed in milliseconds.

@Volly, epicfail is a little slow to understand. He has the ability to understand many things, but just doesn't see the connection between some things. He needs some special help. 8)

Edited by Manadar

Share this post


Link to post
Share on other sites

i was doing some playing around and came up with this not sure what 1 is right both seem to work. What 1 is the right way?

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    If TimerDiff($init) > 600000 Then
        ExitLoop
    EndIf
Wend

Share this post


Link to post
Share on other sites

sweet thanks 4 the help :D so how would i exit the script with Exit after that time not just exit the loop?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend
Exit

Or

$init = TimerInit()

While 1
    If TimerDiff($init) >  600000 Then
        Exit ; Note this says > 600000 instead of < 600000
    EndIf
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend
Exit
Edited by Manadar

Share this post


Link to post
Share on other sites

ty it took ages but i understand now sorry guys 4 taking awhile to understand. Thanks heaps Manadar u always seem to help me.

Share this post


Link to post
Share on other sites

I added a sleep in there so the CPU doesn't go crazy.

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    Sleep(50)
Wend
Exit

Or

$init = TimerInit()

While 1
    If TimerDiff($init) >  600000 Then
        Exit ; Note this says > 600000 instead of < 600000
    EndIf
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    sleep(50)
Wend
Exit

Share this post


Link to post
Share on other sites

ok something else say i have other stuff after my while that i dont want to be done after i exit my loop how would i stop it from doing them? if i use exit it will exit but i want to be able to use my gui still so dont want to fully exit the program.

Share this post


Link to post
Share on other sites

; GUI stuff

$result = _WaitForWindow()
If $result = 1 Then
   ; The window was found
Else
   ; There was a time out
EndIf

Func _WaitForWindow()
    Local $init = TimerInit()
    
    While TimerDiff($init) <  600000
        If WinActive("Untitled -") Then
            Return 1
        EndIf
    Wend
    Return 0
EndFunc

Share this post


Link to post
Share on other sites

sweet thanks.

Share this post


Link to post
Share on other sites

I hope you have learned some things from this thread.

May I ask, what are you building? I've helped you on so many occasions it's made me curious. : )

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

a bot 4 a facebook game lol just wanted to try to learn something new. hehe now i have just learnt how to use this to make error ini and send it to a webhost.

Edited by epicfail

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