goto此时出人意料

Sam*_*erd 4 goto batch-file

@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
Run Code Online (Sandbox Code Playgroud)

我正在尝试为cmd制作一个基于文本的游戏,每当我尝试输入响应时立即关闭,我几乎无法读出"goto此时出乎意料"

pad*_*ddy 7

您没有正确地形成测试.您需要将变量括在双引号中:

if "%input%" == "1" goto Feel
if "%input%" == "2" goto Listen
Run Code Online (Sandbox Code Playgroud)

请注意,在这些之后你需要一个额外的条件来处理他们没有输入1或2的可能性.

您应该考虑使用choice命令而不是set /p.键入choice /?从命令提示.

将来,如果您在提前终止时遇到问题,请从命令提示符运行脚本.这样窗口就不会关闭,你将有足够的时间来阅读错误.

您可以通过按Windows Key- R,键入cmd并按下来快速运行命令提示符Enter