Worin liegt der Fehler? Zufallsprinzip ..

  • Guten Tag,

    ich komme hier nicht weiter, da mein Script bei mir etwas streikt.

    Kann mir bitte jemand sagen, woran es liegt, dass nichts passiert, wenn ich nachdem ich den Button angeklickt habe und ein Bild anklicke?

    Ohne das Zufallsprinzip lief alles einwandfrei.

    Script :

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    $Form = GUICreate("Memory", 226, 226, 192, 124)
    $PicMemory = GUICtrlCreatePic("Memory.jpg", 8, 8, 100, 100)
    $PicMemory2 = GUICtrlCreatePic("Memory.jpg", 112, 8, 100, 100)
    $PicMemory3 = GUICtrlCreatePic("Memory.jpg", 8, 112, 100, 100)
    $PicMemory4 = GUICtrlCreatePic("Memory.jpg", 112, 112, 100, 100)
    $Button1 = GUICtrlCreateButton("Button1", 100, 215, 30, 9)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _Zufallspos()
    EndSwitch
    WEnd

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

    Func _Zufallspos()
    Local $iRnd = Random(1, 2, 1)
    Switch $iRnd
    Case 1
    While 1
    Switch $nMsg
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 1.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 2.jpg")
    EndSwitch
    WEnd
    Case 2
    While 1
    Switch $nMsg
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 2.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 1.jpg")
    EndSwitch
    WEnd
    EndSwitch
    EndFunc

    [/autoit]
  • Ich habe nun mal die While Schleife rausgenommen und es allgemein noch um paar Zeilen verändert.

    Trotzdem funktioniert es noch nicht ;/

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    $Form = GUICreate("Memory", 226, 226, 192, 124)
    $PicMemory = GUICtrlCreatePic("Memory.jpg", 8, 8, 100, 100)
    $PicMemory2 = GUICtrlCreatePic("Memory.jpg", 112, 8, 100, 100)
    $PicMemory3 = GUICtrlCreatePic("Memory.jpg", 8, 112, 100, 100)
    $PicMemory4 = GUICtrlCreatePic("Memory.jpg", 112, 112, 100, 100)
    $Button1 = GUICtrlCreateButton("Button1", 100, 215, 30, 9)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _Zufallspos()
    EndSwitch
    WEnd

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

    Func _Zufallspos()
    Local $iRnd = Random(1, 2, 1)
    Switch $iRnd
    Switch $nMsg
    Case 1
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 1.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 2.jpg")
    Case 2
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 2.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 1.jpg")
    Endswitch
    EndSwitch
    EndFunc

    [/autoit]

    Wie muss ich denn nun vorgehen?

  • Hier noch ein Versuch von mir :

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    $Form = GUICreate("Memory", 226, 226, 192, 124)
    $PicMemory = GUICtrlCreatePic("Memory.jpg", 8, 8, 100, 100)
    $PicMemory2 = GUICtrlCreatePic("Memory.jpg", 112, 8, 100, 100)
    $PicMemory3 = GUICtrlCreatePic("Memory.jpg", 8, 112, 100, 100)
    $PicMemory4 = GUICtrlCreatePic("Memory.jpg", 112, 112, 100, 100)
    $Button1 = GUICtrlCreateButton("Button1", 100, 215, 30, 9)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _Zufallspos()
    EndSwitch
    WEnd

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

    Func _Zufallspos()
    Local $iRnd = Random(1, 2, 1)
    Switch $iRnd
    Case 1
    While 1
    Switch $nMsg
    Case $PicMemory
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 1.jpg")
    Case $PicMemory2
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 2.jpg")
    EndSwitch
    WEnd
    Case 2
    While 1
    Switch $nMsg
    Case $PicMemory
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 2.jpg")
    Case $PicMemory2
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    ExitLoop
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 1.jpg")
    EndSwitch
    WEnd
    EndSwitch
    EndFunc

    [/autoit]

    Nun bin ich aus der While Schleife raus aber es funktioniert noch nicht,
    ;/

    Einmal editiert, zuletzt von Julien (28. Dezember 2011 um 12:54)

  • Hi,
    meinst du so?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    $Form = GUICreate("Memory", 226, 226, 192, 124)
    $PicMemory = GUICtrlCreatePic("Memory.jpg", 8, 8, 100, 100)
    $PicMemory2 = GUICtrlCreatePic("Memory.jpg", 112, 8, 100, 100)
    $PicMemory3 = GUICtrlCreatePic("Memory.jpg", 8, 112, 100, 100)
    $PicMemory4 = GUICtrlCreatePic("Memory.jpg", 112, 112, 100, 100)
    $Button1 = GUICtrlCreateButton("Button1", 100, 215, 30, 9)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _Zufallspos()
    EndSwitch
    WEnd

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

    Func _Zufallspos()
    Local $iRnd = Random(1, 2, 1)
    Switch $iRnd
    Case 1
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 1.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 2.jpg")
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd
    Case 2
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $PicMemory
    sleep(300)
    GUICtrlSetImage($PicMemory, "Memory Bild 2.jpg")
    Case $PicMemory2
    sleep(300)
    GUICtrlSetImage($PicMemory2, "Memory Bild 2.jpg")
    Case $PicMemory3
    sleep(300)
    GUICtrlSetImage($PicMemory3, "Memory Bild 1.jpg")
    Case $PicMemory4
    sleep(300)
    GUICtrlSetImage($PicMemory4, "Memory Bild 1.jpg")
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd
    EndSwitch
    EndFunc

    [/autoit]


    Ich würde an deiner Stelle aber das Konzept nochmals überdenken!

  • Ja, genauso meine ich es. Danke dir. ;)

    Hmm , wieso überdenken? Ich möchte mal so ein Memory schreiben und das später auch mit mehreren Bildern zum üben und anders fällt mir gerade nicht ein wie ich es machen könnte.