Jump to content
Servasius

How to stop the WHILE infinite loop in GUI using button push?

Recommended Posts

Servasius

Hello,

I am new to AutoIT, in fact, this is my first script. I'm trying to create some script to automate some activities within the game. I have managed to get the Auto_Loot_Start function to work but I can't seem to get out of the infinite loop using the button when I press EXIT. I try to find the solution and found some that might work. One of them is to set a HotKey. Though I don't really want to use HotKey since I want to keep it all GUI based. Another solution I read was OnEvent Mode to interrupt the infinite loop. I tried to understand some of the examples that I found online but I don't get it how to implement it in my script. I hope all the experts in here can help me with this problem and please explain your answer in details so I can understand them better.

To make things clearer, The startAutoLoot() function is supposed to send x key in an infinite loop. Which I think I get it to work.

stopAutoLoot() function is supposed to pause the script without closing it. I don't know if I'm doing it right or not.

terminateScript() function is supposed to exit the program/script. This only work only if startAutoLoot() function is not started yet.

startAutoBuff() and startHolyForce() are not implemented yet.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=Z:\GuNkzZ\Documents\RF_Script.kxf
Global $RF_Script = GUICreate("RF_Script", 213, 211, -1, -1)
GUISetFont(8, 400, 0, "Open Sans")
GUISetBkColor(0x000000)
Global $Auto_Loot_Start = GUICtrlCreateButton("Auto_Loot_Start", 8, 8, 195, 33)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Global $Auto_Loot_Stop = GUICtrlCreateButton("Auto_Loot_Stop", 8, 48, 195, 33)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Global $Auto_Buff_Start = GUICtrlCreateButton("Auto_Buff_Start", 8, 88, 195, 33)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Global $Holy_Force_Buff = GUICtrlCreateButton("Holy_Force_Buff", 8, 128, 195, 33)
GUICtrlSetBkColor(-1, 0xFFFFFF)
Global $EXIT = GUICtrlCreateButton("EXIT", 8, 168, 195, 33)
GUICtrlSetFont(-1, 10, 800, 0, "Open Sans")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Auto_Loot_Start
            startAutoLoot()

        Case $Auto_Loot_Stop
            stopAutoLoot()

        Case $Auto_Buff_Start
            startAutoBuff()

        Case $Holy_Force_Buff
            startHolyForce()

        Case $EXIT
            terminateScript()

    EndSwitch
WEnd

Func startAutoLoot()
    if WinExists("RF Online") Then
        WinActivate("RF Online")
    while(1)
        Send("{x}")
        Sleep (100)
    WEnd
    EndIf
EndFunc ;==>Start Auto Loot

Func stopAutoLoot()
    if WinExists("RF Online") Then
        WinActivate("RF Online")
    while(1)
        Sleep (50)
    WEnd
    EndIf
EndFunc ;==>Stop Auto Loot

Func terminateScript()
    Exit
EndFunc ;==>Stop the script

Thank you for the help!

Share this post


Link to post
Share on other sites
TheDcoder

I have not looked your post but you can try ExitLoop which will end the loop.

While True ; Infinite
    Sleep(1000)
    ExitLoop
Wend

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Melba23

Servasius,

Welcome to the AutoIt forum.

Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked.

See you soon with a legitimate question I hope.

TheDcoder,

Please actually read the post before replying - I have seldom seen a thread which made it quite so clear that the code was for a gamebot.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×