Sign in to follow this  
Followers 0
brad25

How to exit A endless while loop

8 posts in this topic

Hi everyone, like the topic says but im using a button to exit the program but once it starts the loop it will not close. any help would be great.

func test()
    
    
    while 1
    $scoord = PixelSearch( 727, 100, 953, 401, 0x9e9e00)
       if not @error Then
        MouseMove ( $scoord[0], $scoord[1])
        sleep(1000)
        MouseMove ( $scoord[0]+40, $scoord[1])
MouseClick("right")
   MouseMove ( $scoord[0]+70, $scoord[1])
        MouseClick("left")
        sleep(1000)
        MouseMove(426, 396)
    
    EndIf
    
WEnd
EndFunc

func exit1()
    if $nMsg=$button2 then Exit
    EndFunc
    
    

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Jumper = GUICreate("Jumper", 188, 81, 409, 433)
$Button1 = GUICtrlCreateButton("Start", 16, 40, 73, 25)
$Button2 = GUICtrlCreateButton("Exit", 96, 41, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
    

    $nMsg = GUIGetMsg()
    
    if $nMsg=$button1 then test()
    if $nMsg=$button2 then exit1()
WEnd

Share this post


Link to post
Share on other sites



#5 ·  Posted (edited)

How did you add it ? Show the code.

Edited by Thlitmi

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The Exit button works if you click it first. If you click the Start button, the script is stuck in an endless loop. That's why clicking on the Exit button after clicking on the Start button does no good. You cannot break into the loop. Consider using an ExitLoop or Return after the MouseMoves have finished or if there is an @error

Func test()
    While 1
        $Scoord = PixelSearch(727, 100, 953, 401, 0x9e9e00)
        If Not @error Then
            MouseMove($Scoord[0], $Scoord[1])
            Sleep(1000)
            MouseMove($Scoord[0] + 40, $Scoord[1])
            MouseClick("right")
            MouseMove($Scoord[0] + 70, $Scoord[1])
            MouseClick("left")
            Sleep(1000)
            MouseMove(426, 396)
            Return
        Else
            Return
        EndIf
    WEnd
EndFunc   ;==>test
FYI, you just need Exit in your Exit1() function. Technically $nMsg and $Button2 are not Global variables and you did not pass them to the function.
Func exit1()
    Exit
EndFunc   ;==>exit1

Edited by Varian

Share this post


Link to post
Share on other sites

"How to exit A endless while loop"

You can't! ... It would not be a endless loop anymore. (o.O)

*hick*


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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