Sign in to follow this  
Followers 0
Bakkoda

multiple function calls

9 posts in this topic

I am writing a small program to send keys to a game that I am developing/beta testing. Currently I have the GUI and functions all set up my only problem is once I stop the current loop I cannot start it again (or do anything really). I am wondering how to step out of the loop but yet be able to click the start button and have the loop start fresh.

I might be approaching the stop check all wrong as I am nto the worlds best programmer when it comes to structure.

#include <GUIConstants.au3>

Opt("MouseCoordMode", 0)
Opt("WinTitleMatchMode", 3)
Opt("PixelCoordMode",0)

Global $fighting = FALSE
$helper_title = "WBK"

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate($helper_title, 204, 204, 20, @DesktopHeight/2+160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
$tab=GUICtrlCreateTab (2, 32, 200, 170)

GUICtrlCreateLabel ("Game Title", 130, 9)
$game_title = GUICtrlCreateInput ("Beta-bzt", 2, 6, 125, 20)

;Rogue GUI
$tab0=GUICtrlCreateTabitem ("Rogue")

    GUICtrlCreateLabel ("Main key", 58, 63)
    $ss_key = GUICtrlCreateInput ("1", 8, 60, 45, 20)
    
    GUICtrlCreateLabel ("Finish key", 58, 88)
    $evis_key = GUICtrlCreateInput ("5", 8, 85, 45, 20)
    
    GUICtrlCreateLabel ("Buff key", 58, 113)
    $snd_key = GUICtrlCreateInput ("6", 8, 110, 45, 20)
    
    GUICtrlCreateLabel ("Attack delay", 58, 138)
    $attack_delay = GUICtrlCreateInput ("2000", 8, 135, 45, 20)

    $r_kill = GUICtrlCreateButton("Start Killing", 6, 173, 80, 25)
    GUICtrlSetOnEvent($r_kill, "RogueKill")
    
    $s_kill = GUICtrlCreateButton("Stop Killing", 118, 173, 80, 25)
    GUICtrlSetOnEvent($s_kill, "StopKill")

;Warrior GUI
$tab1=GUICtrlCreateTabitem ("Warrior")

;GUI Constants
GUISetState(@SW_SHOW)
GUISetFont(10, 300)
WinSetOnTop($helper_title, "", 1);always on top

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

;###################################################################################################

################
;# GUI Functions
;###################################################################################################

################
Func RogueKill()
    If WinExists(GUICtrlRead($game_title)) Then
        WinActivate(GUICtrlRead($game_title))
        
        If ($fighting = FALSE) Then 
            $fighting = TRUE
        EndIf
        
    ;main attack loop
        While $fighting = TRUE
            $i = 0
        ;SS loop
            While $i < 4
                Send("{" & GUICtrlRead($ss_key) & "}")
                Sleep(GUICtrlRead($attack_delay))
                
            ;increment i
                $i = $i + 1
            Wend
        ;eviscerate
            Send("{" & GUICtrlRead($evis_key) & "}")
            Sleep(5000)
            
            If ($fighting = FALSE) Then ExitLoop
        WEnd
        
        MsgBox(0, "Done Killing...", "You stopped me from attacking")
    Else
        MsgBox(0, "Start Killing...", "No active windows found")
    EndIf
EndFunc


;helper functions
Func StopKill()
    $fighting = FALSE
EndFunc

Func CLOSE()
    Exit
EndFunc

Share this post


Link to post
Share on other sites



I haven't an answer for your problem but..

This part is not correct...

Your using Opt("GUIOnEventMode", 1)

So GUIGetMsg() will not work ...

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Cheers

Share this post


Link to post
Share on other sites

Again smashly is right :)

Change your loop to

While 1
   Sleep 100
WEnd

and it will work as intended.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I changed it. I had copied and pasted old code. I still have the same problem though. If I click the stop button the entire script becomes unresponsive. I have to exit out from the system tray and the start button does nothing as well.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Func StopKill()
    Switch @GUI_CtrlId
        Case $s_kill 
            $fighting = FALSE
    EndSwitch
EndFunc

botting WoW ... tut-tut

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Func StopKill()
    Switch @GUI_CtrlId
        Case $s_kill 
            $fighting = FALSE
    EndSwitch
EndFunc

botting WoW ... tut-tut

Heh again, borrowed code from a previous script i wrote.

I still get no response from the script once i exit out of the main loop.basically i need it to call RogueKill() when i hit the start button and when i hit the stop button have it go back to idle state. from there i need to be able to call the RogueKill() function again or any other function. currently as soon as the stop function is called the entire script hangs.

Share this post


Link to post
Share on other sites

Sorry for the delay but ... it was weekend :)

Here it comes a working version - some changes done but it works.

#include <GUIConstants.au3>

Opt("MouseCoordMode", 0)
Opt("WinTitleMatchMode", 3)
Opt("PixelCoordMode",0)

Global $fighting = FALSE
$helper_title = "WBK"

Opt("GUIOnEventMode", 1)
$mainwindow = GUICreate($helper_title, 204, 204, 20, @DesktopHeight/2+160)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
$tab=GUICtrlCreateTab (2, 32, 200, 170)

GUICtrlCreateLabel ("Game Title", 130, 9)
$game_title = GUICtrlCreateInput ("Beta-bzt", 2, 6, 125, 20)

;Rogue GUI
$tab0=GUICtrlCreateTabitem ("Rogue")

    GUICtrlCreateLabel ("Main key", 58, 63)
    $ss_key = GUICtrlCreateInput ("1", 8, 60, 45, 20)
    
    GUICtrlCreateLabel ("Finish key", 58, 88)
    $evis_key = GUICtrlCreateInput ("5", 8, 85, 45, 20)
    
    GUICtrlCreateLabel ("Buff key", 58, 113)
    $snd_key = GUICtrlCreateInput ("6", 8, 110, 45, 20)
    
    GUICtrlCreateLabel ("Attack delay", 58, 138)
    $attack_delay = GUICtrlCreateInput ("2000", 8, 135, 45, 20)

    $r_kill = GUICtrlCreateButton("Start Killing", 6, 173, 80, 25)
    GUICtrlSetOnEvent($r_kill, "start")
    
    $s_kill = GUICtrlCreateButton("Stop Killing", 118, 173, 80, 25)
    GUICtrlSetOnEvent($s_kill, "StopKill")

;Warrior GUI
$tab1=GUICtrlCreateTabitem ("Warrior")

;GUI Constants
GUISetState(@SW_SHOW)
GUISetFont(10, 300)
WinSetOnTop($helper_title, "", 1);always on top

While 1
    Sleep (100)
    If $fighting = TRUE Then RogueKill()
Wend

;###################################################################################################
################
;# GUI Functions
;###################################################################################################
################
Func start()
    $fighting = TRUE
EndFunc

Func RogueKill()
    If WinExists(GUICtrlRead($game_title)) Then
        WinActivate(GUICtrlRead($game_title))
    ;main attack loop
            $i = 0
        ;SS loop
            While $i < 4
                Send("{" & GUICtrlRead($ss_key) & "}")
                Sleep(GUICtrlRead($attack_delay))
            ;increment i
                $i = $i + 1
            Wend
        ;eviscerate
            Send("{" & GUICtrlRead($evis_key) & "}")
            Sleep(5000)
    Else
        MsgBox(0, "Start Killing...", "No active windows found")
    EndIf
EndFunc


;helper functions
Func StopKill()
    Switch @GUI_CtrlId
        Case $s_kill
            $fighting = FALSE
            MsgBox(0, "Done Killing...", "Once the cycle is complete it will stop killing")
    EndSwitch
EndFunc

Func CLOSE()
    Exit
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Sorry for the delay but ... it was weekend :P

Here it comes a working version - some changes done but it works.

I have not idea what this is suppose to do and I obviously don't have the required game for this to work with -- :) As such, when I ran this and clicked on the Start Killing button, I was thrown into a loop. So I made this very small change to the code in the Func RogueKill() section.

Else
        MsgBox(0, "Start Killing...", "No active windows found")
        CLOSE()
    EndIf

Share this post


Link to post
Share on other sites

Good point - I'm sure he will be grateful for this addition :)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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