-1

I'm working on my first game in a batch file and I keep getting the error of "'taken was unexpected at this time'". "taken" is what I'm assigning the variable "shotgun" as. What I'm trying to make is so that if the user hasn't "picked up the shogun" it will make them stay in the current area, but if they did pick it up It will move them to the other "live" area.

: 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
aschipfl
  • 28,946
  • 10
  • 45
  • 77
KriM
  • 11
  • 1
  • 1
    Possible duplicate of [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](http://stackoverflow.com/questions/26386697/why-is-no-string-output-with-echo-var-after-using-set-var-text-on-comman) – Mofi Mar 14 '17 at 05:46
  • Normally I'd agree @Mofi, bit as you can see, there are so many issues that this alone would not solve their dilemma. – Compo Mar 14 '17 at 11:57

1 Answers1

2

You shouldn't have spaces either side of your = character when setting variables, set /p command = would end in a variable named %command %. In much the same way setting a variable to taken should be "shotgun=taken" not shotgun= taken which would set %shotgun% to the value taken (with a leading space). Label names should directly follow the : without a space too, so :barn_right not : barn_right. When setting %shotgun% to taken use Set not Set /P. Normally I'd suggest using Set /P "command=" but in this case, I'd say do not use Set /P at all, use Choice instead. If you want to to check for matches then use ==not = and prefereably not 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
Compo
  • 30,301
  • 4
  • 20
  • 32