TapDancing CrabDemon
TapDancing CrabDemon

Reputation: 13

How do I make a batch file not progress when wrong button is pressed?

I'm working on a long text-based game about a depressed teenager. In the beginning, I used this :

@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

and it worked just fine, if I were to type something that was not an option, it would just refresh the main menu, but then whenever I try and use the "goto (whatever name the tab is)" it wont even let me do any function and if I take it out, it just progresses no matter what I do, heres so more of my code (it's just what I have as of right now) :

:openscomputer
cls
echo.
echo.
echo    *Opens computer*
echo.     
echo.
ping localhost -n 1 >nul
cls
echo.
echo    *Opens computer*
echo     .
echo.
ping localhost -n 1 >nul
cls
echo.
echo    *Opens computer*
echo     ..
echo.
ping localhost -n 1 >nul
cls
echo.
echo    *Opens computer*
echo     ...
echo.
ping localhost -n 1 >nul
cls
echo.
echo    *Opens computer*
echo     ....
echo.
ping localhost -n 1 >nul
cls
echo.
echo    *Opens computer*
echo     .....
echo.
ping localhost -n 2 >nul
cls
goto openedcomputer




:openedcomputer
cls
echo.
echo.
echo          _____________________________
echo.
echo                New Notification!
echo.
echo                  (1) New IM's
echo.
echo          _____________________________
echo.
echo.
echo             (Press any key to )
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.)
set /p %input1%= ">>>>>>>"
if "%input1%" == "1" goto sick1
if "%input1%" == "2" goto bus1 else goto clicked1


: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.
set /p %input%= ">>>>>>>"
if "%input%"=="1" goto cold1
if "%input%"=="2" goto idk1
goto sick1



: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.)
set /p %input%= ">>>>>>>"
if "%input%"=="1" goto dontworry1
if "%input%"=="2" imhere1
goto bus1

I've ALSO tried putting (for instance) (if "%input%"=="1" (goto dontworry1) else (goto bus1) AND STILL it wont let me progress even if I press the right thing, as well as if I take it out, it progressed no matter what I type. Please help. :/

Upvotes: 0

Views: 40

Answers (1)

Sam Denty
Sam Denty

Reputation: 4085

I've simplified your script by using choice /C YN /M ">>>>>>>", this will only allow 1 & 2 to be inputted, therefore removing unnecessary error checking.

See the below script:

@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)

Upvotes: 1

Related Questions