@echo off
color 0a
title Horror Game
echo.
echo.
echo.
echo.
echo Welcome to the game
echo If you get scared
echo Feel free to leave
echo.
echo.
echo You are in a dark room.
echo It is cold.
echo All you hear is a scratching sound
echo near your feet.
echo What do you do?
echo.
echo.
echo 1.) Feel around you
echo 2.) Listen for anything else
set/p input = Command?
if %input% == "1" goto Feel
if %input% == "2" goto Listen
echo.
echo.
:Feel
echo You feel around and hear a growl.
echo As you realize the scratching was
echo on your leg.
echo.
echo You remember nothing else.
pause
end
I am trying to make a text based game for cmd and whenever i try to enter a response is instantly closes and i can barely read out "goto was unexpected at this time"
You did not form your tests correctly. You need to enclose the variable in double-quotes:
if "%input%" == "1" goto Feel
if "%input%" == "2" goto Listen
Note that you need an extra condition after these to deal with the possibility that they didn't enter 1 or 2.
You should consider using the choice
command instead of set /p
. Type choice /?
from the command prompt.
In future, run your script from the command prompt if you're having trouble with premature termination. That way the window won't close on you and you'll have plenty of time to read the error.
You can run a command prompt quickly by pressing -R, typing cmd
and pressing Enter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With