Jump to content

Need help breaking out of a Function early


Recommended Posts

What about - Return

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
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
Link to comment
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 *

Link to comment
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 *

Link to comment
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?

Link to comment
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

NEWHeader1.png

Link to comment
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.

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...