首页 > 解决方案 > 自动检查批处理文件中的输入

问题描述

我目前正在研究批量文本冒险/RPG,以了解更多关于编码的信息,并且我正在尝试实现输入的自动检查(例如玩家类型 1,无需按 Enter 即可通过)。我目前有这个:

echo Type 1 for New Game
echo.
set /p=gamepick
if gamepicker equ 1 goto newgame
if gamepicker neq 1 goto gamepicker

关于如何做到这一点的任何建议?

标签: batch-file

解决方案


在 Windows 命令批处理文件中,功能代码如下:

REM Turn off command echoing to the screen
@ECHO OFF
ECHO.
ECHO.
SET /p GamePick=Type 1 for New Game
IF "%GamePick%"=="1" goto NewGame
REM If the script gets here, the input value was not a 1

:GamePicker
REM Some code to do something
REM and at the end of the code, exit the script
GOTO Exit

:NewGame
REM The input value was a 1 
ECHO We're starting a new game for you!
REM Some game code goes here
REM and at the end of the code, exit the script
GOTO Exit

:Exit
REM This is the end of the script.

推荐阅读