Eine While in einer Func mit einer anderen Func abschalten

  • Hallo Com.


    Der titel sagt alles will mit einem button eine andere func in der eine while ist abbrechen ohne das ganze script zu beenden villt kann man da auch was mit for machen pls help

    mein jetziges script
    [autoit]

    #include <GUIConstants.au3>

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

    $Form1 = GUICreate("", 318, 154, 548, 312)
    GUISetBkColor(0x000000)
    $Label1 = GUICtrlCreateLabel("", 15, 15, 301, 23)
    GUICtrlSetFont(-1, 12, 800, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFFFF)
    $Button1 = GUICtrlCreateButton("Start", 15, 105, 76, 31, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Button2 = GUICtrlCreateButton("Stop", 120, 105, 76, 31, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUISetState(@SW_SHOW)

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

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

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

    Case $Button1
    Global $status = 0
    countdown()

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

    Case $Button1
    countdownstop()

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

    EndSwitch
    WEnd

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

    Func countdown()
    While 1
    Sleep(1000)
    TrayTip("lol","lol",1)

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

    If $status = 1 Then ExitLoop

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

    WEnd
    EndFunc

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

    Func countdownstop()
    Global $status = 1
    EndFunc

    [/autoit]
  • Erstmal:

    Ich bin der Meinung du solltest deine Globalen Variablen auch am Anfang definieren - und nicht erst in einer Funktion.

    Ich mache es bisher so:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

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

    $Form1 = GUICreate("", 318, 154, 548, 312)
    GUISetBkColor(0x000000)
    $Label1 = GUICtrlCreateLabel("", 15, 15, 301, 23)
    GUICtrlSetFont(-1, 12, 800, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFFFF)
    $Button1 = GUICtrlCreateButton("Start", 15, 105, 76, 31, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Button2 = GUICtrlCreateButton("Stop", 120, 105, 76, 31, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUISetState(@SW_SHOW)

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

    ;Global $nMsg
    ;Global $status = 0

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetState($Button1, $GUI_DISABLE)
    countdown()
    EndSwitch
    WEnd

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

    Func countdown()
    While 1
    If GUIGetMsg() = $Button2 Then
    MsgBox(0,"ABBRUCH","Es wurde STOP gedrückt")
    GUICtrlSetState($Button1, $GUI_ENABLE)
    ExitLoop
    EndIf
    TrayTip("lol","lol",1)
    WEnd
    EndFunc

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

    Ich frage also in meiner Funktion einfach regelmäßig den Button mit ab.

    hab den Beitrag noch mal bearbeitet (Skript nochmal aufgeräumt)

    BLinz