Jump to content

Closure Help


Askali
 Share

Recommended Posts

This is my first post here and I'd like to say thanks to all the help I've gotten by browsing the past few days while creating my first little program.

Now I have an issue that I've tried fixing 100 different ways that I've seen posted all over these forums, but I just cannot get it to work, so any advice would be so appreciated.

My program runs and does the main things I'd like it to do, however no matter what I do the x or the stop button will not close the program after it's started running

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=wow.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{F1}", "_instructions")
HotKeySet("{F2}", "_set_NPC")
HotKeySet("{F3}", "_set_TEXT")
HotKeySet("{F4}", "_set_SLOT")
HotKeySet("{F10}", "_exit")

$Main = GUICreate("Hallow's End", 240, 282, 16, 16)

GUISetIcon("C:\Users\Jamie\Desktop\hallows\wow.ico")

$coords    = GUICtrlCreateGroup("Co-Ordinates", 8, 78, 225, 122)

$NPC_Label = GUICtrlCreateLabel("NPC Location:", 24, 102, 86, 17)

$value    = IniRead("C:\HallowsEnd.ini", "Co-Ords", "NPC_PosX", "0")
$NPC_PosX = GUICtrlCreateInput($value, 128, 99, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)

$value    = IniRead("C:\HallowsEnd.ini", "Co-Ords", "NPC_PosY", "0")
$NPC_PosY = GUICtrlCreateInput($value, 176, 99, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)

$Text_Label = GUICtrlCreateLabel("Text Location:", 24, 135, 86, 17)

$value     = IniRead("C:\HallowsEnd.ini", "Co-Ords", "Text_PosX", "0")
$Text_PosX = GUICtrlCreateInput($value, 128, 132, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)

$value     = IniRead("C:\HallowsEnd.ini", "Co-Ords", "Text_PosY", "0")
$Text_PosY = GUICtrlCreateInput($value, 176, 132, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)

$Slot_Label = GUICtrlCreateLabel("Slot Location:", 24, 168, 83, 17)

$value     = IniRead("C:\HallowsEnd.ini", "Co-Ords", "Slot_PosX", "0")
$Slot_PosX = GUICtrlCreateInput($value, 128, 165, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)

$value     = IniRead("C:\HallowsEnd.ini", "Co-Ords", "Slot_PosY", "0")
$Slot_PosY = GUICtrlCreateInput($value, 176, 165, 40, 21)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_DISABLE)


GUICtrlCreateGroup("", -99, -99, 1, 1)

$StatusBar = _GUICtrlStatusBar_Create($Main)

Dim $StatusBar_PartsWidth[2] = [120, -1]
    _GUICtrlStatusBar_SetParts($StatusBar, $StatusBar_PartsWidth)
    _GUICtrlStatusBar_SetText($StatusBar, "", 0)
    _GUICtrlStatusBar_SetText($StatusBar, "", 1)
    _GUICtrlStatusBar_SetMinHeight($StatusBar, 20)

$Start          = GUICtrlCreateButton("Start", 8, 214, 105, 33, $WS_GROUP)
    GUICtrlSetOnEvent($Start, "_perform")

$Stop           = GUICtrlCreateButton("Stop", 8, 214, 105, 33, $WS_GROUP)
    GUICtrlSetOnEvent($Stop, "_exit")

$Instructions   = GUICtrlCreateButton("Instructions", 128, 214, 105, 33, $WS_GROUP)
    GUICtrlSetOnEvent($Instructions, "_instructions")

$value          = IniRead("C:\HallowsEnd.ini", "WoW", "Location", "C:\Program Files (x86)\World of Warcraft\")
$Location_Label = GUICtrlCreateLabel("WoW Location:", 16, 21, 97, 17)
$Location_Input = GUICtrlCreateInput($value, 120, 16, 113, 21)

$Password_Label = GUICtrlCreateLabel("Account Password:", 16, 51, 97, 17)
$Password_Input = GUICtrlCreateInput("", 120, 46, 113, 21, $ES_PASSWORD)

GUICtrlSetState($stop, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

;---------- Functions ----------

Func _perform()

            GUICtrlSetState($start, $GUI_HIDE)
            GUICtrlSetState($stop, $GUI_SHOW)
            
            IniWrite("C:\HallowsEnd.ini", "WoW", "Location", GUICtrlRead($Location_Input))
            
            TrayTip("Hallow's End", "Processing started, press F10 or Stop to cancel", 5, 1)
            
            $count = 0
            
            While 1
                
                $count += 1

                $plural = ""
                IF $count <> 1 Then
                    $plural = "s"
                EndIf

                ;Run(GUICtrlRead($Location_Input) & "WoW.exe", GUICtrlRead($Location_Input), @SW_MAXIMIZE)
                ;WinWaitActive("World of Warcraft")

                    Sleep(8000); 8 Sec, Loading Delay

                AutoItSetOption("SendKeyDelay", 20)
                Send(GUICtrlRead($Password_Input) & "{ENTER}")

                    Sleep(10000); 14 Sec, Login Delay

                Send("{ENTER}")

                    Sleep(14000); 14 Sec, Loading Delay

                MouseClick('Right', GUICtrlRead($NPC_PosX), GUICtrlRead($NPC_PosY), 1, 1); Middle of screen for NPC

                    Sleep(3000); 3 Sec, Loading Delay

                MouseClick('Left', GUICtrlRead($Text_PosX), GUICtrlRead($Text_PosY), 1, 1); Click Trick or Treat
                _GUICtrlStatusBar_SetText($statusbar, $count & " Trick or Treat" & $plural, 1)

                    Sleep(5000); 3 Sec, Loading Delay

                Send("b");

                    Sleep(1000); 1 Sec

                MouseClick('Right', GUICtrlRead($Slot_PosX), GUICtrlRead($Slot_PosY), 1, 1); Use Item

                    Sleep(5000); 3 Sec, Loading Delay

                IF ProcessExists("WoW.exe") Then
                    ProcessClose("WoW.exe")
                EndIf

                MouseMove(0, 0, 0)

                    $timer = TimerInit()
                    $wait  = 3593000

                    While( TimerDiff($timer) < $wait )

                        $seconds = TimerDiff($timer) / 1000
                        $diff    = $seconds - ($wait / 1000)

                        $minutes    = Int($diff / 60)
                        $secondsRem = $diff - ($minutes * 60)

                        $minutes    = $minutes * -1
                        $secondsRem = $secondsRem * -1
                        $time       = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)

                        _GUICtrlStatusBar_SetText($statusbar, $time & " left on debuff", 0)

                        sleep(1000);

                    WEnd

            WEnd

EndFunc

Func _exit()

    Exit

EndFunc

Func _instructions()

    MsgBox(64, "Hallow's End Information", "Below are the keybindings required to setup the bot:" & @CRLF & @CRLF & "F2 - Sets the NPC location using the current mouse position" & @CRLF & "F3 - Sets the location of the Trick or Treat text" & @CRLF & "        Same position as the set home location dialog" & @CRLF & "F4 - Sets the bag slot location where the treat will go (make sure there are no free slots before it)" & @CRLF & "F10 - Closes the program after process has been started" & @CRLF & @CRLF & "The best way to use this is to find a quiet innkeeper, zoom your camera right in and use the keys mentioned above to configure the options." & @CRLF & @CRLF & "Once your cooldown is ready, close WoW, start the bot and it will (hopefully) fully automate the process for you!" & @CRLF & @CRLF & "Good Luck!")

EndFunc

Func _set_NPC()

    IF WinActive("World of Warcraft") Then
    
        $MousePos = MouseGetPos()

            GUICtrlSetData($NPC_PosX, $MousePos[0]);
            GUICtrlSetData($NPC_PosY, $MousePos[1]);

            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "NPC_PosX", $MousePos[0])
            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "NPC_PosY", $MousePos[1])

    EndIf

EndFunc

Func _set_Text()

    IF WinActive("World of Warcraft") Then

        $MousePos = MouseGetPos()

            GUICtrlSetData($Text_PosX, $MousePos[0]);
            GUICtrlSetData($Text_PosY, $MousePos[1]);

            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "Text_PosX", $MousePos[0])
            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "Text_PosY", $MousePos[1])

    EndIf

EndFunc

Func _set_Slot()

    IF WinActive("World of Warcraft") Then

        $MousePos = MouseGetPos()

            GUICtrlSetData($Slot_PosX, $MousePos[0]);
            GUICtrlSetData($Slot_PosY, $MousePos[1]);

            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "Slot_PosX", $MousePos[0])
            IniWrite("C:\HallowsEnd.ini", "Co-Ords", "Slot_PosY", $MousePos[1])

    EndIf

EndFunc

Thank you in advance

Link to comment
Share on other sites

You should expand your

While 1
 Sleep(10)
WEnd

to something like:

While 1
    $sMsg = GUIGetMsg()
    Select
        Case $sMsg = $GUI_EVENT_CLOSE 
            Exit
    EndSelect
WEnd

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water

No, you're wrong. He is in GUIOnEventMode and cannot use GuiGetMsg().

@Askali

You have two issues. First, you need to set the event for when the X button is clicked.

GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

Second, once you enter the perform function you are stuck in your second loop. The problem here is that none of your OnEvent functions will be triggered until you exit that loop. This is just the way AutoIt works. You need to return back to the main loop before your buttons will function again. You might want to reconsider the architecture of your program at this point, or consider switching to GuiGetMsg() mode which you can use from anywhere, including a secondary loop.

Edited by wraithdu
Link to comment
Share on other sites

@water

No, you're wrong. He is in GUIOnEventMode and cannot use GuiGetMsg().

@Askali

You have two issues. First, you need to set the event for when the X button is clicked.

GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

Second, once you enter the perform function you are stuck in your second loop. The problem here is that none of your OnEvent functions will be triggered until you exit that loop. This is just the way AutoIt works. You need to return back to the main loop before your buttons will function again. You might want to reconsider the architecture of your program at this point, or consider switching to GuiGetMsg() mode which you can use from anywhere, including a secondary loop.

I was using the getmsg switch loop for the longest time and only changed it to eventmode after I saw a few posts suggesting it for others; however neither of these methods allow it to be closed.

And the program is ment to be an on indefinite loop until you close it, so I'm not sure what my other options are

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