Problem mit Else

  • Spoiler anzeigen
    [autoit]

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

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

    #region variablen

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

    $start = 1
    $title = ""
    $prodi_h = 100
    $prodi_l = 100
    $prodi_e = 100
    ;100 pro minute
    $mainbuild = "Hauptgebäude"
    $font = "Comic Sans MS"
    $time_start = 30000
    $level_main = $start
    $level_wood = $start
    $wood = "Holz:"
    $clay = "Lehm:"
    $iron = "Eisen:"
    $error_ress = "Nicht genug Rohstoffe vorhanden"
    $build = "Ausbauen"
    $ress = 100
    $ressH = $ress
    $ressL = $ress
    $ressE = $ress
    $woodcutter = "Holzfäller"
    $claypit = "Lehmgrube"
    $ironmine = "Eisenmine"
    ;holzfäller kosten
    $cost_wood2H = 40
    $cost_wood2L = 20
    $cost_wood2E = 10

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

    $cost_wood3H = 60
    $cost_wood3L = 40
    $cost_wood3E = 20

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

    $cost_wood4H = 100
    $cost_wood4L = 60
    $cost_wood14E = 30

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

    #endregion variablen

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

    AdlibRegister ( "_prodi", $time_start )

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

    #region gui

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

    $Form1_1 = GUICreate( $title, 547, 368, 235, 193)
    $Label_main = GUICtrlCreateLabel( $mainbuild, 24, 144, 91, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_mainLevel = GUICtrlCreateLabel( $level_main, 24, 168, 49, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_wood = GUICtrlCreateLabel( $wood, 24, 24, 36, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_clay = GUICtrlCreateLabel( $clay, 24, 48, 38, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_iron = GUICtrlCreateLabel( $iron, 24, 72, 40, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Button_buildMain = GUICtrlCreateButton( $build, 24, 200, 75, 25)
    $Label_ressH = GUICtrlCreateLabel( $ressH, 72, 24, 35, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_ressL = GUICtrlCreateLabel( $ressL, 72, 48, 32, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_ressE = GUICtrlCreateLabel( $ressE, 72, 72, 35, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font )
    $label_prodiH = GUICtrlCreateLabel( $prodi_h, 208, 16, 43, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_prodiL = GUICtrlCreateLabel( $prodi_l, 208, 40, 40, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_prodiE = GUICtrlCreateLabel( $prodi_e, 208, 64, 43, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label1 = GUICtrlCreateLabel("Pro 30 Sekunden", 280, 40, 69, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label2 = GUICtrlCreateLabel( $woodcutter, 144, 144, 67, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font )
    $Label_woodcutter = GUICtrlCreateLabel( $level_wood, 144, 168, 49, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font )
    $Button_buildWood = GUICtrlCreateButton( $build, 136, 200, 75, 25)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button_buildWood ;holzfäller ausbauen

    ;stufe 4


    ;stufe 3


    ;stufe 2

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

    If $level_wood = $start Then ;if stufe 1

    If $ressH > $cost_wood2H Then ;holz2

    If $ressL > $cost_wood2L Then ;lehm2

    If $ressE > $cost_wood2E Then ;eisen2
    ;neue ressis
    $ressH = $ressH - $cost_wood2H
    $ressL = $ressL - $cost_wood2L
    $ressE = $ressE - $cost_wood2E

    ;stufe hoch
    $level_wood = $level_wood +1
    GUICtrlSetData ( $Label_woodcutter, $level_wood )

    ;neue prodi
    $prodi_h = $prodi_h / 2
    $prodi_h = $prodi_h * 3

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

    Else

    MsgBox ( 16, $title, $error_ress )
    Else

    MsgBox ( 16, $title, $error_ress )
    Else
    MsgBox ( 16, $title_error_ress )

    EndIf
    EndIf
    EndIf
    EndIf


    EndSwitch
    WEnd

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

    #endregion

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

    Func _prodi ()
    $ressH = $ressH + $prodi_h
    $ressL = $ressL + $prodi_l
    $ressE = $ressE + $prodi_e
    GUICtrlSetData ( $Label_ressH, $ressH )
    GUICtrlSetData ( $Label_ressL, $ressL )
    GUICtrlSetData ( $Label_ressE, $ressE )
    EndFunc

    [/autoit]

    AutoIt zeigt mir immer an, dass zuviele Else da sind.
    Aber wenn ich ein Else wegnehme, kommt wieder die gleiche, etc.

  • Ich würde dir ja gerne helfen, aber das sieht mir ein wenig nach einem Bot für das Spiel die Stämme oder etwas Ähnlichem aus. Ich ziehe es einfach vor nur die zu unterstützen die sich an die Forenregelen halten, deshalb frage ich lieber erstmal nach dem Zweck des Programmes. ;)

  • Ein Spiel wo man ein Dorf/Stadt aufbaut.
    Bin nicht weit und erst bei den Rohstoffproduzenten.

  • Das ist KEIN Bot. ich habs grad mal gezogen und zum Laufen gebracht.
    Ich schätze das soll später mal ein kleines Strategiespiel werden...

    Spoiler anzeigen
    [autoit]

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

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

    #Region variablen

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

    $start = 1
    $title = ""
    $prodi_h = 100
    $prodi_l = 100
    $prodi_e = 100
    ;100 pro minute
    $mainbuild = "Hauptgebäude"
    $font = "Comic Sans MS"
    $time_start = 30000
    $level_main = $start
    $level_wood = $start
    $wood = "Holz:"
    $clay = "Lehm:"
    $iron = "Eisen:"
    $error_ress = "Nicht genug Rohstoffe vorhanden"
    $build = "Ausbauen"
    $ress = 100
    $ressH = $ress
    $ressL = $ress
    $ressE = $ress
    $woodcutter = "Holzfäller"
    $claypit = "Lehmgrube"
    $ironmine = "Eisenmine"
    ;holzfäller kosten
    $cost_wood2H = 40
    $cost_wood2L = 20
    $cost_wood2E = 10

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

    $cost_wood3H = 60
    $cost_wood3L = 40
    $cost_wood3E = 20

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

    $cost_wood4H = 100
    $cost_wood4L = 60
    $cost_wood14E = 30

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

    #EndRegion variablen

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

    AdlibRegister("_prodi", $time_start)

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

    #Region gui

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

    $Form1_1 = GUICreate($title, 547, 368, 235, 193)
    $Label_main = GUICtrlCreateLabel($mainbuild, 24, 144, 91, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_mainLevel = GUICtrlCreateLabel($level_main, 24, 168, 49, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_wood = GUICtrlCreateLabel($wood, 24, 24, 36, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_clay = GUICtrlCreateLabel($clay, 24, 48, 38, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_iron = GUICtrlCreateLabel($iron, 24, 72, 40, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Button_buildMain = GUICtrlCreateButton($build, 24, 200, 75, 25)
    $Label_ressH = GUICtrlCreateLabel($ressH, 72, 24, 35, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_ressL = GUICtrlCreateLabel($ressL, 72, 48, 32, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_ressE = GUICtrlCreateLabel($ressE, 72, 72, 35, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $label_prodiH = GUICtrlCreateLabel($prodi_h, 208, 16, 43, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_prodiL = GUICtrlCreateLabel($prodi_l, 208, 40, 40, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_prodiE = GUICtrlCreateLabel($prodi_e, 208, 64, 43, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label1 = GUICtrlCreateLabel("Pro 30 Sekunden", 280, 40, 69, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label2 = GUICtrlCreateLabel($woodcutter, 144, 144, 67, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Label_woodcutter = GUICtrlCreateLabel($level_wood, 144, 168, 49, 22)
    GUICtrlSetFont(-1, 10, 400, 0, $font)
    $Button_buildWood = GUICtrlCreateButton($build, 136, 200, 75, 25)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button_buildWood ;holzfäller ausbauen

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

    ;stufe 4

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

    ;stufe 3

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

    ;stufe 2

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

    If $level_wood = $start Then ;if stufe 1

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

    If $ressH > $cost_wood2H Then ;holz2

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

    If $ressL > $cost_wood2L Then ;lehm2

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

    If $ressE > $cost_wood2E Then ;eisen2
    ;neue ressis
    $ressH = $ressH - $cost_wood2H
    $ressL = $ressL - $cost_wood2L
    $ressE = $ressE - $cost_wood2E

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

    ;stufe hoch
    $level_wood = $level_wood + 1
    GUICtrlSetData($Label_woodcutter, $level_wood)

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

    ;neue prodi
    $prodi_h = $prodi_h / 2
    $prodi_h = $prodi_h * 3

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

    Else

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

    MsgBox(16, $title, $error_ress)
    EndIf
    Else

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

    MsgBox(16, $title, $error_ress)
    EndIf
    Else
    MsgBox(16, $title, $error_ress)
    EndIf
    EndIf

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

    EndSwitch
    WEnd

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

    #EndRegion gui

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

    Func _prodi()
    $ressH = $ressH + $prodi_h
    $ressL = $ressL + $prodi_l
    $ressE = $ressE + $prodi_e
    GUICtrlSetData($Label_ressH, $ressH)
    GUICtrlSetData($Label_ressL, $ressL)
    GUICtrlSetData($Label_ressE, $ressE)
    EndFunc ;==>_prodi

    [/autoit]

    lg
    Mars(i)

  • Du musst Jede If Abfrage einzeln behandeln und einzeln beenden.

    Du kannst nicht während eine If abfrage noch offen ist eine zweite Öffnen und dann ein Else für die Erste einbauen.

    [autoit]

    If $a = 0 Then

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

    If $b = 1 Then
    _Blubb()
    Else
    _Bla()
    EndIf

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

    Else
    _Blubber()
    EndIf

    [/autoit]

    Man muss die Ifabfragen also erst wieder zu machen (mit Endif), bevor man ein Else einsetzen kann.

    Und es ist wichtig, dass du deinen Variablen zuweist wo sie gültig sind.

    [autoit]

    Global $a = 5 ; $a ist im kompletten Skript vorhanden.
    Local $a = 7 ; $a ist nur in der Funktion vorhanden in der es deklariert wurde.
    Dim ; Ist blöd. Sollte man nicht verwenden :P

    [/autoit]

    lg