Start - Stop Buttons (bei stop soll die aktuellle schleife beendet werden) WIE?

  • Hi leute, bin neu bei autoit und probiere gerade ien bissechen mit dem Gui rum. bisher konnte ich mir viel aus der doku erlesen aba hänge jetzt leider trotz dem. ich will ein programm mit einem start und einem stop button schreiben. beim startbutton wird eine endlosschleife aufgerufen die ich aba mit dem stop button ohne zeitverzögerung beenen will... hab schon bisel rumproiert aba bisher war meine einzigste lösung das ich den stop button über ne prüfung in die endlosschleife eifüge und das nach jeder handlung... das is ziemlich doof und ich hab immer nch ne zeitverzögerung drinne... manchmal von 10-15 sec. wisst ihr vielleicht ne lösung wie ich über nen button ne aktive endlosschleife sofort beenden kann?

    hier ma nen beispiel mit nem count...

    [autoit]

    #include <GUIConstants.au3>
    Global $Counter
    Global $Add
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 203, 91, 193, 125)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 8, 174, 40, $SS_CENTER)
    GUICtrlSetFont(-1, 20, 800, 0, "Arial Black")
    $Start = GUICtrlCreateButton("Start", 16, 56, 75, 25, 0)
    $Stop = GUICtrlCreateButton("Stop", 104, 56, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Func _Add()
    Do
    $Add = $Add + 1
    GUICtrlSetData ( $Label1, $Add)
    Sleep(150)
    Until $Counter = 0
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    $Counter = 1
    _Add()
    Case $Stop
    $Counter = 0
    MsgBox(0, "Stop", "Zähler wurde Angehalten.")
    EndSwitch
    WEnd

    [/autoit]

    das mit dem counter is mir gerade eingefallen aba bringt ach nix... der zähler läufft weiter wenn ich stop drücke... :(

    2 Mal editiert, zuletzt von Vega e7 (3. November 2008 um 19:09)

    • Offizieller Beitrag

    Vielleicht so:

    Spoiler anzeigen
    [autoit]


    #include<GUIConstantsEx.au3>
    #include<StaticConstants.au3>
    Global $Counter, $Add, $Time
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 203, 91, 193, 125)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 8, 174, 40, $SS_CENTER)
    GUICtrlSetFont(-1, 20, 800, 0, "Arial Black")
    $Start = GUICtrlCreateButton("Start", 16, 56, 75, 25, 0)
    $Stop = GUICtrlCreateButton("Stop", 104, 56, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    $Time = TimerInit()
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    $Counter = 1
    Case $Stop
    $Counter = 0
    MsgBox(0, "Stop", "Zähler wurde Angehalten.")
    EndSwitch
    If $Counter And TimerDiff($Time) >= 1000 Then
    $Time = TimerInit()
    $Add = $Add + 1
    GUICtrlSetData($Label1, $Add)
    EndIf
    WEnd

    [/autoit]
  • thx :)

    leider funzt das nich wenn ich mehrere sleep's habe... also wenn ich komplexere scripte auf anhieb stoppen will...

    das z.b:

    [autoit]

    #include<GUIConstantsEx.au3>
    #include<StaticConstants.au3>
    Global $Counter, $Add, $Time
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 203, 91, 193, 125)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 8, 174, 40, $SS_CENTER)
    GUICtrlSetFont(-1, 20, 800, 0, "Arial Black")
    $Start = GUICtrlCreateButton("Start", 16, 56, 75, 25, 0)
    $Stop = GUICtrlCreateButton("Stop", 104, 56, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $Time = TimerInit()
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    $Counter = 1
    Case $Stop
    $Counter = 0
    MsgBox(0, "Stop", "Zähler wurde Angehalten.")
    EndSwitch
    If $Counter And TimerDiff($Time) >= 7000 Then
    $Time = TimerInit()
    $Add = $Add + 1
    GUICtrlSetData($Label1, $Add)
    Sleep(2000)
    $Add = $Add + 10
    GUICtrlSetData($Label1, $Add)
    Sleep(2000)
    $Add = $Add + 100
    GUICtrlSetData($Label1, $Add)
    Sleep(2000)
    $Add = $Add + 1000
    GUICtrlSetData($Label1, $Add)
    Sleep(2000)
    $Add = $Add + 10000
    GUICtrlSetData($Label1, $Add)
    Sleep(2000)
    EndIf
    WEnd

    [/autoit]

    wie kann ich sowas unterbrechen?

  • Man könnte es ja vlielleicht auch mit AdLibEnable() lösen, aber es kommt eben ganz darauf an was man machen will. ;)

  • also es geht eigendlich darum das ich nen größeres script geschrieben habe (bot) unteranderem sind 2 schleifen drin die nach monstern suchen un eine die heilt solange bs das monster tot ist... diese schleifen dauern halt langebis die bedingung erfühlt ist und dann beendet werden kann... eigendlich störts nich nur will ich das jetzt mit dem gui halt starten und stoppen... dachte das ichs alllein hin bekomme aba der bot wurde immer erst angehalten wenn eine schleife beendet war...

  • ok... dann sorry für den unnötigen thread... mus ich halt wohl alleine weiter knobeln... :) aba thx für die denkanstöße :)

    EDIT: war ne super idee von mignon (hoffe dir ises nich unangenehm), thx an dieser stelle :) warscheinlich nich sauber programmiert aba es funzt irgendwie :)


    [autoit]

    #include <GUIConstants.au3>
    Global $Counter
    Global $Add
    AdlibEnable("Halt",50)
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 203, 91, 193, 125)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 8, 174, 40, $SS_CENTER)
    GUICtrlSetFont(-1, 20, 800, 0, "Arial Black")
    $Start = GUICtrlCreateButton("Start", 16, 56, 75, 25, 0)
    $Stop = GUICtrlCreateButton("Stop", 104, 56, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Func _Add()
    Do
    $Add = $Add + 1
    GUICtrlSetData ( $Label1, $Add)
    Sleep(10000)
    Until $Counter = 0
    EndFunc
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    $Counter = 1
    _Add()
    EndSwitch
    WEnd
    Func Halt()
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Stop
    $Counter = 0
    MsgBox(0, "Stop", "Zähler wurde Angehalten.")
    EndSwitch
    EndFunc

    [/autoit]

    2 Mal editiert, zuletzt von Vega e7 (3. November 2008 um 23:20)