While - WEnd Problem

  • Hallo,
    ich möchte nicht stören, aber ich kapiere es einfach nicht warum ich den Script nicht zum laufen kriege. Ich habe es auch schon mit "do - until" oder "switch - case - endswitch" probiert aber da ging es auch nicht. Hier erstmal mein Script:

    [autoit]

    While
    $random = Random(1, 10, 1)
    $answer = InputBox("Good Luck!", "Please choose a number between 1 and 10.")
    If $random <> $answer Then
    MsgBox(16, "Failed", "Your choosed number (" & $answer & ") wasn't the winning number. The winning number was " & $random & ". Just try it again.")
    #include <GUIConstantsEx.au3>
    opt("GUIOnEventMode", 1)
    GUIcreate("Try it one more time", 300, 300)
    GUIsetstate(@sw_show)
    $ID = GUIctrlcreatebutton("I want to try it again", 100, 100)
    GUIctrlsetonEvent($ID, "_msg")
    While 1
    Sleep(1000)
    WEnd
    Func _msg()
    Msgbox(0, "lol", "hi")
    EndFunc

    ElseIf $random == $answer Then
    MsgBox(48, "Good!", "You are really lucky, the random choosed number was " & $random & " and your number was " & $answer & ", too. Do you want to try it again with a random number between 1 and 20?") ExitLoop
    #include <GUIConstantsEx.au3>
    opt("GUIOnEventMode", 1)
    GUIcreate("Try it one more time", 300, 300)
    GUIsetstate(@sw_show)
    $ID1 = GUIctrlcreatebutton("I want to try it again with a number between 1 and 20", 100, 100)
    GUIctrlsetonEvent($ID, "_msg")
    While 1
    Sleep(1000)
    WEnd
    Func _msg()
    Msgbox(48, "Oh my God", "You are extremly lucky...or you tried this stupid mini-game 200 Times. I hope you just had Luck!")
    EndFunc
    WEnd

    [/autoit]

    Das Problem ist das er meint, dass es zu dem WEnd (ganz am Ende) ein While geben muss, das meiner meinung aber schon ganz am anfang des Scripts steht.
    Bei "Do - Until" und "Switch - Case - Endswitch" hat ihm auch immer entweder der untere Teil (until oder endswitch) oder der obere Teil (Do oder Switch) gefehlt
    Vielleicht funktioniert es wegen des GUI-Codes mittendrin nicht oder weil er das erste WEnd schon mit dem ersten While als zusammengehörig zählt.
    Hoffentlich könnt ihr mir helfen.
    lg. Benny

  • Func _msg()
    Msgbox(48, "Oh my God", "You are extremly lucky...or you tried this stupid mini-game 200 Times. I hope you just had Luck!")
    EndFunc
    Das deklariert eine Funktion, die benutzt du, indem du einfach nur _msg() schreibst.
    Einmal in keienr Schleife usw. die Funktion deklareiren und schon fertig

    PS:
    Includes nach oben!

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    While
    $random = Random(1, 10, 1)
    $answer = InputBox("Good Luck!", "Please choose a number between 1 and 10.")
    If $random <> $answer Then
    MsgBox(16, "Failed", "Your choosed number (" & $answer & ") wasn't the winning number. The winning number was " & $random & ". Just try it again.")

    opt("GUIOnEventMode", 1)
    GUIcreate("Try it one more time", 300, 300)
    GUIsetstate(@sw_show)
    $ID = GUIctrlcreatebutton("I want to try it again", 100, 100)
    GUIctrlsetonEvent($ID, "_msg")
    While 1
    Sleep(1000)
    WEnd


    ElseIf $random == $answer Then
    MsgBox(48, "Good!", "You are really lucky, the random choosed number was " & $random & " and your number was " & $answer & ", too. Do you want to try it again with a random number between 1 and 20?") ExitLoop
    #include <GUIConstantsEx.au3>
    opt("GUIOnEventMode", 1)
    GUIcreate("Try it one more time", 300, 300)
    GUIsetstate(@sw_show)
    $ID1 = GUIctrlcreatebutton("I want to try it again with a number between 1 and 20", 100, 100)
    GUIctrlsetonEvent($ID, "_msg")
    While 1
    Sleep(1000)
    WEnd

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

    Func _msg()
    Msgbox(0, "lol", "hi")
    EndFunc
    WEnd

    [/autoit]
  • Ich glaube sowas sollte rauskommen, oder?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    Opt("GUIOnEventMode", 1)

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

    $Weiter = False
    $Maximal = 10

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

    $hGUI_Fail = GUICreate("Try it one more time", 300, 300)
    $ID_Fail = GUICtrlCreateButton("I want to try it again", 100, 100)
    GUICtrlSetOnEvent($ID_Fail, "_msg")

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

    $hGUI_Success = GUICreate("Try it one more time", 300, 300)
    $ID_Success = GUICtrlCreateButton("I want to try it again with a number between 1 and 20", 100, 100)
    GUICtrlSetOnEvent($ID_Success, "_msg")

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

    While 1
    $random = Random(1, $Maximal, 1)
    $answer = InputBox("Good Luck!", "Please choose a number between 1 and " & $Maximal & ".")

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

    If $random <> $answer Then
    MsgBox(16, "Failed", "Your choosed number (" & $answer & ") wasn't the winning number. The winning number was " & $random & ". Just try it again.")
    GUISetState(@SW_SHOW, $hGUI_Fail)
    $Weiter = False
    While Not $Weiter
    Sleep(10)
    WEnd
    GUISetState(@SW_HIDE, $hGUI_Fail)
    ElseIf $random == $answer Then
    MsgBox(48, "Good!", "You are really lucky, the random choosed number was " & $random & " and your number was " & $answer & ", too. Do you want to try it again with a random number between 1 and " & $Maximal + 10 & "?")
    GUISetState(@SW_SHOW, $hGUI_Success)
    $Weiter = False
    While Not $Weiter
    Sleep(10)
    WEnd
    GUISetState(@SW_HIDE, $hGUI_Success)
    $Maximal = $Maximal + 10
    EndIf
    WEnd

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

    Func _msg()
    Switch @GUI_CtrlId
    Case $ID_Success, $ID_Fail
    $Weiter = True
    EndSwitch
    EndFunc ;==>_msg

    [/autoit]
  • *g* habs zum Spaß auch mal gebastelt.
    immer wieder interessant wie unterschiedlich die lösungen doch sind.
    Und doch ist es vom Prinzip das gleiche Spiel^^

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3> ; gehört an den anfang und auch nur einmal
    Opt("GUIOnEventMode", 1); Optionen normalerweise auch immer an den anfang des Scriptes
    $number = 10

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

    $gui = GUICreate("Try it one more time", 300, 150); gui erstellen
    $ID = GUICtrlCreateButton("", 10, 50, 280, 25)
    GUICtrlSetOnEvent($ID, "raetsel"); mit dem button lässt sich später das rätsel ausführen
    GUISetState(@SW_HIDE, $gui); .. und auf versteckt setzen
    GUISetOnEvent($GUI_EVENT_CLOSE, "quit"); damit man das Skript auch beenden kann

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

    raetsel(); erstes ausführen des rätsels

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

    While 1
    Sleep(1000)
    WEnd

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

    Func quit(); damit man das Skript auch beenden kann
    Exit
    EndFunc

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

    Func raetsel()
    GUISetState(@SW_HIDE, $gui)
    $random = Random(1, $number, 1)
    $answer = InputBox("Good Luck!", "Please choose a number between 1 and " & $number & ".")
    If $random <> $answer Then
    MsgBox(16, "Failed", "Your choosed number (" & $answer & ") wasn't the winning number. The winning number was " & $random & ". Just try it again.")
    GUICtrlSetData($ID, "I want to try it again"); damit sich der Text des Buttons ändert
    Else ; nur else reicht weil entweder ist es falsch oder richtig
    $number = $number + 10; den Bereich zum raten größer machen
    $msg = MsgBox(48, "Good!", "You are really lucky, the random choosed number was " & $random & " and your number was " & $answer & ", too. Do you want to try it again with a random number between 1 and 20?")
    GUICtrlSetData($ID, "I want to try it again with a number between 1 and " & $number); damit sich der Text des Buttons ändert
    EndIf
    GUISetState(@SW_SHOW, $gui)
    EndFunc

    [/autoit]
  • Danke für die schnellen Antworten.
    Nun bin ich wieder ein wenig schlauer. :thumbup: