batch-file - goto在这个时候出乎意料

标签 batch-file goto

@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

我正在尝试为 cmd 制作一个基于文本的游戏,每当我尝试输入响应时都会立即关闭,我几乎无法读出“此时转到意外”

最佳答案

你没有正确地形成你的测试。您需要用双引号将变量括起来:

if "%input%" == "1" goto Feel
if "%input%" == "2" goto Listen

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

您应该考虑使用 choice命令而不是 set /p .类型 choice /?从命令提示符。

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

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

关于batch-file - goto在这个时候出乎意料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19898451/

相关文章:

batch-file - 如何列出除一个以外的所有目录?

c - 如何在 while 循环中转换此 goto 循环?

c - 当C中没有左侧时,&&运算符会做什么?

batch-file - 处理批处理文件中带空格的尾部反斜杠和目录名称

batch-file - 如何使用 microsoft .bat 文件检测文件是否为空?

batch-file - 具有常量的变量的批处理文件比较失败

windows - 为什么批处理文件中的特殊字符打印为问号?

go - 协程和 `goto` 之间的区别?

c# - 在这种情况下可以使用 "goto"吗?

perl - 如何在 Perl 的上层范围内本地化变量?