按下错误按钮后,如何使批处理文件不进行?

时间:2016-09-22 19:52:22

标签: batch-file

我正在制作一个关于一个沮丧的少年的长文本游戏。一开始,我用过这个:

% a 10000000000000
Hello!
0
160
114
78
24
9
0
0

它工作得很好,如果我输入的东西不是一个选项,它只会刷新主菜单,但每当我尝试使用“goto(无论名称是什么名称)”时它都不会让我做任何功能,如果我把它拿出来,无论我做什么都会进步,继续我的代码更多(这就是我现在所拥有的):

@echo off
echo.
echo      So, tell me about yourself, what is your name?
echo.
echo.
set /p uname=>>>>>>>"
echo.
cls
echo.
echo.
echo      I really do hope this is your last drink, %uname%...
ping localhost -n 2 >nul
cls
goto mainmenu
::::::::::::::::::::::::::::::::::::::::::::::
:mainmenu
cls
echo.
echo         ________________________________________________
echo.
echo          Do you wish to log onto your computer %uname%?
echo.
echo.
echo          Yes or no? If no, you will be sent right back
echo          here, so you may as well, what better do you
echo          have to do in your life anyways?
echo.
echo         ________________________________________________
echo.
set /p input=">>>>>>>"
if "%input%"== "yes" goto openscomputer
if "%input%"== "no" goto mainmenu
goto mainmenu
pause >nul

我也尝试过(例如)(如果“%input%”==“1”(goto dontworry1)else(转到bus1)并且仍然不会让我进步即使我按下正确的东西,因为好吧,如果我把它拿出来,无论我输入什么,它都会进展。请帮助。:/

1 个答案:

答案 0 :(得分:1)

我使用choice /C YN /M ">>>>>>>"简化了您的脚本,这只允许1&要输入2,因此删除不必要的错误检查。

请参阅以下脚本:

@echo off
    echo.
    echo      So, tell me about yourself, what is your name?
    echo.
    echo.
    set /p "uname=>>>>>>>"
    echo.
    cls
    echo.
    echo.
    echo      I really do hope this is your last drink, %uname%...
    timeout /nobreak 1 >nul
:mainmenu
    cls
    echo.
    echo         ________________________________________________
    echo.
    echo          Do you wish to log onto your computer %uname%?
    echo.
    echo.
    echo          Yes or no? If no, you will be sent right back
    echo          here, so you may as well, what better do you
    echo          have to do in your life anyways?
    echo.
    echo         ________________________________________________
    echo.
    choice /C YN /M ">>>>>>>"
    if errorlevel 2 (goto mainmenu) else (goto openscomputer)
:openscomputer
    set ".="
    :openCompLoop
        cls
        echo.
        echo.
        echo    *Opens computer*
        echo.   %.%  
        echo.
        if "%.%"=="................" goto openedcomputer
        ping localhost -n 1 >nul
        set .=%.%.
goto :openCompLoop


:openedcomputer
    cls
    echo.
    echo.
    echo          _____________________________
    echo.
    echo                New Notification!
    echo.
    echo                  (1) New IM's
    echo.
    echo          _____________________________
    echo.
    echo.
    echo            (Press any key to check)
    echo.
    echo.
    pause >nul
goto clicked1


:clicked1
    cls
    echo          _____________________________
    echo.
    echo            London has messaged you!
    echo.
    echo            London : Hey! Just got
    echo            back from school, where
    echo            were you today? No one
    echo            saw you. Are you okay?
    echo.
    echo.           Messaged recieved 2:45PM         
    echo.
    echo          _____________________________
    echo.
    echo.
    echo    1) Yeah I'm here, I'm sorry I wasn't feeling well so I stayed home.
    echo    2) Sorry, I missed the bus, haha!
    echo.
    echo    (Type which number you wish to say to London.)
    echo.
    choice /C 12 /M ">>>>>>>"
if errorlevel 2 (goto sick1) else (goto bus1)


:sick1
    cls
    echo          _____________________________
    echo.
    echo            London has messaged you!
    echo.
    echo            London : What do you have?
    echo            Are you going to be okay?
    echo.            
    echo.           Messaged recieved 2:47PM         
    echo.
    echo          _____________________________
    echo.
    echo.
    echo    (Type which number you wish to say to London.)
    echo.
    echo    1) I have a cold.
    echo    2) I don't know.
    echo.
    choice /C 12 /M ">>>>>>>"
if errorlevel 2 (goto cold1) else (goto idk1)

:bus1
    cls
    echo          _____________________________
    echo.
    echo            London has messaged you!
    echo.
    echo            London : OMG you had me so
    echo            worried! XD
    echo.
    echo.           Messaged recieved 2:47PM         
    echo.
    echo          _____________________________
    echo.
    echo    (Type which number you wish to say to London.)
    choice /C 12 /M ">>>>>>>"
if errorlevel 2 (goto dontworry1) else (goto :imhere1)