Jump to content

skip func in a while loop


 Share

Recommended Posts

just a slight change...

Local $NowHour
While 1
    If Not $NowHour Or $NowHour <> @HOUR Then
        YourFunction()
        $NowHour = @HOUR
    EndIf
;do other code here
    Sleep(10) ;shortend the sleep for less pause between checking and doing stuff
WEnd
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

would this still work if im doing other stuff in the while loop. so it just checks to see if its been a houre after everything if not it willstilldo other stuff and if its been the hour it willdo my func?

Pretty much, but if you want ALL runs of your function to be 60 minutes (give or take however long the rest of your code in your loop) to process, you will need to look at timer functions like TimerInint() & _TimerDiff(); If you start this script at 12:59PM, the next run will be when the hour is at 13(1PM) so the first 2 runs would only be one minute apart. The subsequent runs would be roughly 60 minutes apart. You could remedy this by storing the Hour & minute and then check to see if the hour has changed and the minute is the same (12:59 to 1:59 to 2:59, etc) or measuring the TimerDiff so it is 60 minutes Edited by Varian
Link to comment
Share on other sites

Here is an example with TimerInint(); This solves the afore mentioned dilemma

$Begin = TimerInit()
While 1
    $Dif = Floor(TimerDiff($Begin) / 60000) ;Returns Elapsed Time in minutes
    If $Dif = 60 Then
        YourFunction()
        $Begin = TimerInit() ;resets the timer
    EndIf
    ;Rest of your Script Here
    Sleep(10) ;small idle to avoid CPU throttling
WEnd
Edited by Varian
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...