Jump to content
Sign in to follow this  
PerryRaptor

Need help breaking out of a Function early

Recommended Posts

Share this post


Link to post
Share on other sites

This is the function that I need a method to breakout of.

Func CountDown()
If $array[3] = "" Then Exit(1)
$Config = $array[3]
$CommunityPatch = IniRead($Config, "COMMUNITY", "Patch", "")
$LaunchTimerM = IniRead($Config, "CDTIMER","LaunchTimer", 2)
$begin = TimerInit()
$LaunchTimer = $launchTimerM * 60000
$LaunchTimer1 = $LaunchTimer /2
$LaunchTimer2 = $LaunchTimer /4

While TimerDiff($begin) <= $LaunchTimer
    ChatBox("Count Down Timer Started with " & $LaunchTimerM & " minutes... ")
    Sleep($LaunchTimer1)    
    ChatBox("Count Down Time Remaining is " & $LaunchTimer1 /60000 & " minutes...")
    Sleep($LaunchTimer2)
    ChatBox("Count Down Time Remaining is " & $LaunchTimer2 /60000 & " minutes... ")
    Sleep($LaunchTimer2)
    ControlClick( $CommunityPatch, "", "EXECUTE")
    Sleep(700)
WEnd
EndFunc
Edited by PerryRaptor

Share this post


Link to post
Share on other sites

This is the function that I need a method to breakout of.

what's wrong with return statement at the right place?

If $condition Then return

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

you mean, inside the While...Wend Loop have a line:

If $condition Then return

yes, $condition is just a place holder. Replace with whatever "test" your wnat!


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

May be I'm not thinking through this...If I make $Array[5] Global at the beginning then this should work.

The "While TimerDiff($begin) <= $LaunchTimer WEnd" part loops every 700ms looking to see if $array[2] is equal to "%StopTimer".

This part of the code will continue to step through line be line until the end...Right?

If $array[2] = "%StopTimer" Then Return

ChatBox("Count Down Timer Started with " & $LaunchTimerM & " minutes... ")

Sleep($LaunchTimer1)

ChatBox("Count Down Time Remaining is " & $LaunchTimer1 /60000 & " minutes...")

Sleep($LaunchTimer2)

ChatBox("Count Down Time Remaining is " & $LaunchTimer2 /60000 & " minutes... ")

Sleep($LaunchTimer2)

ControlClick( $CommunityPatch, "", "EXECUTE")

So if another function elsewhere sets $array[2] = "%StopTimer" then this CountDown function will stop?

Share this post


Link to post
Share on other sites

Maybe...

Dim $retrun = 0

Func CountDown()
If $array[3] = "" Then Exit(1)
$Config = $array[3]
$CommunityPatch = IniRead($Config, "COMMUNITY", "Patch", "")
$LaunchTimerM = IniRead($Config, "CDTIMER","LaunchTimer", 2)
$begin = TimerInit()
$LaunchTimer = $launchTimerM * 60000
$LaunchTimer1 = $LaunchTimer /2
$LaunchTimer2 = $LaunchTimer /4

While TimerDiff($begin) <= $LaunchTimer
    ChatBox("Count Down Timer Started with " & $LaunchTimerM & " minutes... ")
    Cycle($LaunchTimer1)
        If $retrun = 1 then Return
    ChatBox("Count Down Time Remaining is " & $LaunchTimer1 /60000 & " minutes...")
    Cycle($LaunchTimer2)
    If $retrun = 1 then Return
    ChatBox("Count Down Time Remaining is " & $LaunchTimer2 /60000 & " minutes... ")
    Cycle($LaunchTimer2)
    If $retrun = 1 then Return
    ControlClick( $CommunityPatch, "", "EXECUTE")
    Sleep(700)
WEnd
EndFunc


Func Cycle($aTime)
    $iCycle = TimerInit()
    While $iCycle < $aTime
        If $retrun = 1 then Return
        Sleep(100)
    WEnd
EndFunc

EDIT ; $iCycle may need to be "difference" or ???

maybe even better $aTime x 1000 or ???

This overall idea should work... I've used it

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

I added TimerDiff() to get the function to work properly; however, I still cannot break out of the function.

Func Cycle($aTime)
    $iCycle = TimerInit()
    While TimerDiff($iCycle) < $aTime
        If $retrun = 1 then Return
        Sleep(100)
    WEnd
EndFunc

I wonder if a DllCall to a Windows Timer would work. Unfortunately I do not know how to do this.

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  

×
×
  • Create New...