Button reagieren nicht solang func läuft

  • Hallo. wollte ein mal probieren ein spiel zu schreiben und hab ne frage:

    Wie kann ich machen das die anderen Button auch funktionieren während der eine läuft?
    Will mit allen 3 Button gleichzeitig abbauen können.


    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Global $startN=500
    Global $startH=300
    Global $startS=200

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Vorräte", 747, 600, 190, 122)
    $Button1 = GUICtrlCreateButton("Nahrung abbauen", 16, 40, 99, 25, 0)
    $Button2 = GUICtrlCreateButton("Stein abbauen", 136, 40, 99, 25, 0)
    $Button3 = GUICtrlCreateButton("Holz abbauen", 256, 40, 99, 25, 0)
    $Label1 = GUICtrlCreateLabel("Nahrung", 16, 8, 45, 17)
    $Label2 = GUICtrlCreateLabel("Stein", 136, 8, 28, 17)
    $Label3 = GUICtrlCreateLabel("Holz", 256, 8, 25, 17)
    $Label4 = GUICtrlCreateLabel("500", 16, 100, 50, 20)
    $Label5 = GUICtrlCreateLabel("200", 136, 100, 50, 20)
    $Label6 = GUICtrlCreateLabel("300", 256, 100, 50, 20 )
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $vorkommenN1=Random ( 200, 1000, 1 )
    $vorkommenH1=Random ( 100, 500, 1 )
    $vorkommenS1=Random ( 50, 250, 1 )

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    abbauenN()
    Case $Button2
    abbauenS()
    Case $Button3
    abbauenH()
    EndSwitch
    WEnd

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

    Func abbauenN()
    GUICtrlSetData ( $Button1, "wird abgebaut..." )
    For $N=$startN To $vorkommenN1+$startN Step +10
    Sleep ( 1000 )
    GUICtrlSetData ( $Label4, $N )
    Next
    EndFunc

    Func abbauenS()
    GUICtrlSetData ( $Button2, "wird abgebaut..." )
    For $S=$startS To $vorkommenS1+$startS Step +10
    Sleep ( 1000 )
    GUICtrlSetData ( $Label5, $S )
    Next
    EndFunc

    Func abbauenH()
    GUICtrlSetData ( $Button3, "wird abgebaut..." )
    For $H=$startH To $vorkommenH1+$startH Step +15
    Sleep ( 1000 )
    GUICtrlSetData ( $Label6, $H )
    Next
    EndFunc

    [/autoit]

    mfg Greek

    • Offizieller Beitrag

    Funktionen, die Du über einen Event (z.B. Buttonklick) aufrufst, musst Du so schnell wie möglich wieder verlassen, weil sonst keine weiteren Events abgearbeitet werden können.
    Dein Problem könnte man so lösen:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Global $startN = 500
    Global $startH = 300
    Global $startS = 200

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Vorräte", 747, 600, 190, 122)
    $Button1 = GUICtrlCreateButton("Nahrung abbauen", 16, 40, 99, 25, 0)
    $Button2 = GUICtrlCreateButton("Stein abbauen", 136, 40, 99, 25, 0)
    $Button3 = GUICtrlCreateButton("Holz abbauen", 256, 40, 99, 25, 0)
    $Label1 = GUICtrlCreateLabel("Nahrung", 16, 8, 45, 17)
    $Label2 = GUICtrlCreateLabel("Stein", 136, 8, 28, 17)
    $Label3 = GUICtrlCreateLabel("Holz", 256, 8, 25, 17)
    $Label4 = GUICtrlCreateLabel("500", 16, 100, 50, 20)
    $Label5 = GUICtrlCreateLabel("200", 136, 100, 50, 20)
    $Label6 = GUICtrlCreateLabel("300", 256, 100, 50, 20)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $vorkommenN1 = Random(200, 1000, 1)
    $vorkommenH1 = Random(100, 500, 1)
    $vorkommenS1 = Random(50, 250, 1)

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

    $abbauN = 0
    $abbauS = 0
    $abbauH = 0
    AdlibEnable('abbau', 1000)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    abbauenN()
    Case $Button2
    abbauenS()
    Case $Button3
    abbauenH()
    EndSwitch
    WEnd

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

    Func abbau()
    If $abbauN > 0 Then
    $abbauN -= 10
    GUICtrlSetData($Label4, GUICtrlRead($Label4) + 10)
    If $abbauN <= 0 Then GUICtrlSetData($Button1, "Leer")
    EndIf
    If $abbauS > 0 Then
    $abbauS -= 10
    GUICtrlSetData($Label5, GUICtrlRead($Label5) + 10)
    If $abbauS <= 0 Then GUICtrlSetData($Button2, "Leer")
    EndIf
    If $abbauH > 0 Then
    $abbauH -= 10
    GUICtrlSetData($Label6, GUICtrlRead($Label6) + 10)
    If $abbauH <= 0 Then GUICtrlSetData($Button3, "Leer")
    EndIf
    EndFunc

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

    Func abbauenN()
    GUICtrlSetData($Button1, "wird abgebaut...")
    $abbauN = $vorkommenN1
    EndFunc ;==>abbauenN

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

    Func abbauenS()
    GUICtrlSetData($Button2, "wird abgebaut...")
    $abbauS = $vorkommenS1
    EndFunc ;==>abbauenS

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

    Func abbauenH()
    GUICtrlSetData($Button3, "wird abgebaut...")
    $abbauH = $vorkommenH1
    EndFunc ;==>abbauenH

    [/autoit]