Jump to content

Any way to 'Break' a Function? So it stops executing...


Recommended Posts

Hey guys,

Wonderin if anyone knows how to stop a function from completing if an If--Then statement becomes true, Im having a problem with detecting one thing with an If--Then statment that calls a dif, function if the expression is true, But after that function is done, the one called before it finishes and ruins things, since its wayyy out of order. Thanks guys,

p.s Im pretty sure thats called 'Break' in C++ but in autoit, break is comething totally different....

*WoW Dev Projects: AFK Tele Bot development journalSimple Player Pointer Scanner + Z-Teleport*My Projects: coming soon.Check out my WoW Dev wiki for patch 3.0.9!http://www.wowdev.wikidot.com

Link to comment
Share on other sites

put it in a loop?

$i=0

do

if then

else

$i=1

this()

endif

until $i=1

iseem to have troubles understanding what your saying

Link to comment
Share on other sites

'Break' in C++ only terminates a loop (While, If, etc) not a function. In AutoIt, ExitLoop does the same thing. There are a number of ways to achieve what you what, but I can't think of any particularly elegant ways to do it. One obvious way would be a flag and contain the remainder of the function in an If loop so that once the sub-function executes, the remainder of the primary function does not.

$keepgoing = true
Func 1
  Do some stuff
  Func2()
  if $keepgoing then
    Do some more stuff
  endif
endfunc
func 2
  Do some stuff
  $keepgoing = false
endfunc

Edit; Ha! Good thinking Authenticity! I should've thought of that option lol

Edited by Khab
Link to comment
Share on other sites

This is how I do it, not sure if that's what you're looking for.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $loop = 0

$BreakLoop = GUICreate("Break Loop", 218, 101, 193, 125)
$Status = GUICtrlCreateLabel("Loop : ", 24, 10, 75, 25, 0)
$GO = GUICtrlCreateButton("GO", 24, 48, 65, 25, 0)
$Cancel = GUICtrlCreateButton("Cancel", 104, 48, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GO
            loop()
    EndSwitch
WEnd

Func loop()
While 1
    
        GUICtrlSetData($Status, "Loop in Progress: " & $loop)
        
            $nMsg = GUIGetMsg()                                     
                If $nMsg = $Cancel Then 
                    $Abort = MsgBox(36, "Cancel?", "Are you sure you want to cancel?")
                        If $Abort = 6 Then
                            ExitLoop
                            Return
                        EndIf
                EndIf
        $loop = $loop + 1
WEnd
EndFunc ;loop

Hey guys,

Wonderin if anyone knows how to stop a function from completing if an If--Then statement becomes true, Im having a problem with detecting one thing with an If--Then statment that calls a dif, function if the expression is true, But after that function is done, the one called before it finishes and ruins things, since its wayyy out of order. Thanks guys,

p.s Im pretty sure thats called 'Break' in C++ but in autoit, break is comething totally different....

Link to comment
Share on other sites

  • 2 weeks later...

#gfunk999

I got a problem to exit from a loop with a SLEEP inside it.

Im gonna use your code as an exemple. I click on CANCEL to ExitLoop, but it doesnt work.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $loop = 0

$BreakLoop = GUICreate("Break Loop", 218, 101, 193, 125)
$Status = GUICtrlCreateLabel("Loop : ", 24, 10, 75, 25, 0)
$GO = GUICtrlCreateButton("GO", 24, 48, 65, 25, 0)
$Cancel = GUICtrlCreateButton("Cancel", 104, 48, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GO
            loop()
    EndSwitch
WEnd

Func loop()
While 1
    GUICtrlSetData($Status, "Loop in Progress: " & $loop)
    $nMsg = GUIGetMsg()
    If $nMsg = $Cancel Then
        $Abort = MsgBox(36, "Cancel?", "Are you sure you want to cancel?")
        If $Abort = 6 Then
            ExitLoop
            Return
        EndIf
    Else
        Sleep(500)
        $loop = $loop + 1
        Sleep(500)
    EndIf
WEnd
EndFunc ;loop

Any idea?

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