“此时此刻意外

时间:2017-03-13 23:33:50

标签: batch-file

我正在批处理文件中处理我的第一个游戏而且我一直收到错误 “'此时拍摄意外''。 “被采取”是我将变量“shotgun”指定为。我想要做的是,如果用户没有“拿起幕府将军”,它将使他们留在当前区域,但如果他们确实捡起它将它们移动到另一个“现场”区域

: barn

    echo. You enter the barn, it's creeky and it's dark, just as it is outside.
    echo.
    echo. You wonder if anything of use is in this barn.
    echo.
    echo. Should you check under the staircase to the left or to the right?
    echo.
    set /p command =
    echo.
    if %command% equ right goto barn_right
    if %command% equ left goto barn_left_die

        : barn_left_die
        if %shotgun% equ taken goto barn_left_live
        echo. You hear creeking in the floorboards to the right, an infected jumps at you tearing you into pieces.
        echo.
        echo. YOU ARE DEAD
        echo.
        pause

            : barn_left_live
            echo. You hear creeking in the floorboards to the right, you kill the infected that jumps at you with your shotgun!
            echo. You decide to go to a different building, do you go to the shed or house?
            echo.
            set /p command =
            echo.
            if %command% = shed goto shed
            if %command% = house goto house

        : barn_right
        echo. You see a glint in the dark, it appears to be the moon light reflecting off the steel of a shotgun barrel.
        echo.
        echo. You take the shotgun.
        echo.
        set /p shotgun = taken
        echo. Should you now go to the house, shed, or check underneath the left staircase?
        echo.
        set /p command =
        echo.
        if %command% = shed goto shed_die
        if %command% = house goto house_die
        if %command% = left goto left_staircase_die
        pause

1 个答案:

答案 0 :(得分:2)

设置变量时,=字符的任何一侧都不应有空格,set /p command =将以名为%command %的变量结尾。以同样的方式设置要采用的变量应该是"shotgun=taken"而不是shotgun= taken,这会将%shotgun%设置为值taken (带有前导空格)。标签名称应该直接跟在:之后,而不是空格,因此:barn_right不是: barn_right。将%shotgun%设置为taken时,请使用Set而不是Set /P。通常我建议使用Set /P "command=",但在这种情况下,我说完全不使用Set /P,而是使用Choice。如果您想查看匹配项,请使用==而不是=,而不是equ

Echo( You enter the barn, it's creeky and it's dark, just as it is outside.
Echo(
Echo( You wonder if anything of use is in this barn.
Echo(
Echo( Should you check under the staircase to the left or to the right?
Echo(
Choice /C LR
If ErrorLevel 2 GoTo barn_right

:barn_left_die
If /I "%shotgun%"=="taken" GoTo barn_left_live
Echo( You hear creaking in the floorboards to the right, an infected jumps at you tearing you into pieces.
Echo(
Echo( YOU ARE DEAD
Echo(
Timeout -1 /NoBreak

:barn_left_live
Echo( You hear creaking in the floorboards to the right, you kill the infected that jumps at you with your shotgun!
Echo(
Echo( You decide to go to a different building, do you go to the shed or house?
Echo.
Choice /C HS
If ErrorLevel 2 GoTo shed
GoTo house

:barn_right
Echo( You see a glint in the dark, it appears to be the moon light reflecting off the steel of a shotgun barrel.
Echo(
Echo( You take the shotgun.
Echo(
Set "shotgun=taken"
Echo( Should you now go to the house, shed, or check underneath the left staircase?
Echo(
Choice /C LHS
If ErrorLevel 3 goto shed_die
If ErrorLevel 2 goto house_die
GoTo left_staircase_die
Timeout -1 /NoBreak