Jump to content
Sign in to follow this  
onestcoder

Lose Gui Control in Functions

Recommended Posts

onestcoder

I keep haveing this problem with many of my scripts. For example I create a button on my gui to run a pause funtion. but when I pause it the button no longer works. Same goes for another script of mine were while the funtions are activated I can nolonger use the gui controls. What I'm I overlooking???? Here is a short throw together script to show you my problem.

#include <GUIConstants.au3>
$gui = GUICreate("Auto Hunter", 100, 33, 0, 0, -1, $WS_EX_TOPMOST)
Global $Paused
$x = Int(1 + Random(20))
$button_1 = GUICtrlCreateButton(">>>", 5, 4, 25, 25)
GUICtrlSetState($button_1, $GUI_FOCUS)
$n2 = GUICtrlCreateButton("[X]", 65, 4, 25, 25)
$p2 = GUICtrlCreateButton("||", 35, 4, 25, 25)
GUISetState()
Do
    $msg = GUIGetMsg()
    If $msg = $button_1 Then
        Call('hunt')
        If @error Then ContinueLoop
    EndIf
    If $msg = $n2 Then
        Exit
    EndIf
    If $msg = $p2 Then
        Call("TogglePause")
    EndIf
Until $msg = $GUI_EVENT_CLOSE
; Hunt function
Func hunt()
    While 1
        Sleep(5000)
        Send("{NUMPAD8 DOWN}");starts your character running
        Send("{NUMPAD0 $x}");cycles through $x npc's
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(10000)
        Send("{NUMPAD8 UP}")
        Sleep(30000)
    WEnd
EndFunc  ;==>hunt
; Pause function
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause
; Exit function
Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites
pecloe

before i look any closer why are you using "call" ?

Share this post


Link to post
Share on other sites
GaryFrost

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $Paused = False, $hunting = False
$gui = GUICreate("Auto Hunter", 100, 33, 0, 0, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
Global $Paused
$x = Int(1 + Random(20))
$button_1 = GUICtrlCreateButton(">>>", 5, 4, 25, 25)
GUICtrlSetOnEvent($button_1, "hunt")
GUICtrlSetState($button_1, $GUI_FOCUS)
$n2 = GUICtrlCreateButton("[X]", 65, 4, 25, 25)
GUICtrlSetOnEvent($n2, "Terminate")
$p2 = GUICtrlCreateButton("||", 35, 4, 25, 25)
GUICtrlSetOnEvent($p2, "TogglePause")
GUISetState()
While 1
   Sleep(10)
   While $hunting = True
      ToolTip("hunting",0,0)
      Sleep(5000)
      Send("{NUMPAD8 DOWN}");starts your character running
      Send("{NUMPAD0 $x}");cycles through $x npc's
      Sleep(500)
      Send("{ENTER}")
      Sleep(500)
      Send("{ENTER}")
      Sleep(10000)
      Send("{NUMPAD8 UP}")
      Sleep(30000)
   WEnd
WEnd

; Hunt function
Func hunt()
    If $hunting = False And $Paused = True Then 
        TogglePause()
    Else
        $hunting = True
    EndIf
EndFunc  ;==>hunt

; Pause function
Func TogglePause()
   $Paused = Not $Paused
    $hunting = Not $hunting
   If $Paused = False Then
      ToolTip("")
   ElseIf $Paused = True Then
      Sleep(100)
      ToolTip('Script is "Paused"', 0, 0)
   EndIf
EndFunc  ;==>TogglePause

; Exit function
Func Terminate()
   Exit 0
EndFunc  ;==>Terminate

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
jvanegmond

I had the same problem.. but then i realised i didn't need this at all.. So, no solution came out eventually, but i just wanted to let you know it's not just you

Share this post


Link to post
Share on other sites
pecloe

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc;==>TogglePause

this is meant to be used with a hotkey, the script is getting stuck in the while/wend loop

edit; nvm gafrost fixed the wholt thing before i could even read the original code! boy have i got a lot to learn!

Edited by pecloe

Share this post


Link to post
Share on other sites
onestcoder

Global $Paused = False, $hunting = False

Its not working. I get an erro


Need a website: http://www.iconixmarketing.com

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.