Jump to content

How to I can stop the loop


Recommended Posts

Hello everyone, I am a new member of Autoit, I am writing a small script. I want when I click the button start function Finduck start and when I click stop Function Finduck stop and exit loop in function Finduck. But it not working when I click stop. 
Please help me.

quackquack.au3

Link to comment
Share on other sites

48 minutes ago, huuhayho said:

But it not working when I click stop. 

... ...
Func FindDuck()
    While $isRunning
    Switch GUIGetMsg() ; otherwise you will never know.
        Case $btnStop
            $isRunning = False
            Return
    EndSwitch
    Local $checkDucker = PixelSearch(3456, 755, 3763, 877, 0xEEDF58)
... ...

I'm  helping because this is not game related. Otherwise I'd be going against forum rules. :)   

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

 

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

HotKeySet("^x", "Terminate")

Opt("GUIOnEventMode", 1) ;***

$hGUI = GUICreate("Duck Search", 300, 150, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

Global $btnStart = GUICtrlCreateButton("Start", 20, 40, 100, 30)
GUICtrlSetOnEvent(-1, "btnStart")

Global $btnStop = GUICtrlCreateButton("Stop", 160, 40, 100, 30)
GUICtrlSetOnEvent(-1, "btnStop")

Global $lblStatus = GUICtrlCreateLabel("Nhấn start để bắt đầu chương trình", 20, 80, 260, 20)
Global $isRunning = False

Global $hLabel = GUICtrlCreateLabel("", 50, 100, 200, 50)
GUICtrlSetFont($hLabel, 16, 800)

Global $remainingTime = 0

GUISetState(@SW_SHOW)


;**********************************
While 1

    If $isRunning = True Then FindDuck()

WEnd
;**********************************

;--------------------------------------------------------------------------------------------------------------------------------
Func Terminate()
    ConsoleWrite("Terminating program..." & @CRLF)
    Exit
EndFunc   ;==>Terminate
;--------------------------------------------------------------------------------------------------------------------------------
Func FindDuck()
    Local $checkDucker = PixelSearch(3456, 755, 3763, 877, 0xEEDF58)
    If IsArray($checkDucker) Then
        GUICtrlSetData($lblStatus, "Đã tìm thấy vịt mẹ")
        SoundPlay("C:\Users\dinhh\Desktop\alert.mp3")
        $remainingTime = 0
        MouseMove($checkDucker[0] + 10, $checkDucker[1] + 10, 0)
        For $i = 1 To 10
            MouseClick("left")
            Local $checkClaim = PixelSearch(3456, 546, 3763, 877, 0x34BF14)
            If IsArray($checkClaim) Then
                MouseMove($checkClaim[0], $checkClaim[1], 10)
                Sleep(500)
                MouseClick("left")
                $remainingTime = 29 * 60
                UpdateTime()
                $remainingTime = 0
                ;GUICtrlSetData($lblStatus, "Chương trình sẽ tạm dừng 25 phút")
                ;Sleep(25 * 60 * 1000)
                ExitLoop
            EndIf
            Sleep(500)
        Next
    Else
        GUICtrlSetData($lblStatus, "Không tìm thấy vịt mẹ")
        ConsoleWrite("Khong tim thay vit me" & @CRLF)
        Sleep(3000)
    EndIf
EndFunc   ;==>FindDuck
;--------------------------------------------------------------------------------------------------------------------------------
Func UpdateTime()
    While $remainingTime > 0
        If $remainingTime > 0 Then
            Local $mins = Int($remainingTime / 60)
            Local $secs = Mod($remainingTime, 60)
            GUICtrlSetData($hLabel, "Còn lại: " & StringFormat("%02d:%02d", $mins, $secs))
            $remainingTime -= 1
            Sleep(1000)
        Else
            GUICtrlSetData($hLabel, "Coming soon...")
        EndIf
    WEnd
EndFunc   ;==>UpdateTime
;--------------------------------------------------------------------------------------------------------------------------------
Func btnStart()
    $isRunning = True
    ConsoleWrite("$isRunning=" & $isRunning & @CRLF)
EndFunc   ;==>btnStart
;--------------------------------------------------------------------------------------------------------------------------------
Func btnStop()
    $isRunning = False
    ConsoleWrite("$isRunning=" & $isRunning & @CRLF)
EndFunc   ;==>btnStop
;--------------------------------------------------------------------------------------------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

6 hours ago, argumentum said:

this is not game related

How can you be so sure, "findDuck" and translating the Vietnamese "Mother Duck has been found" and "Mother duck could not be found", but the code doesnt include any ducks to be found, it looks with pixelsearch to find some Ducks somewhere else. :)

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

... one of my early scripts was to farm in farmville2. I needed to bond with my sister and she would play that game, but to me gaming was stupid. But then again I needed to have something in common and that was a good way to participate. In any case, when we start coding we need an incentive and many find it in silly games and from a pedagogical point of view it's ok with me. Nonetheless the disclaimer in regards to forum rules must be brought up to enlighten the new forum user so he/she don't get in trouble in this forum site.

So @huuhayho, don't be a stranger and come back for any non-game related questions ( as again, the forum rules are strongly against gaming, eula, etc.:gathering:

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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