Search code examples
if-statementbatch-filecmdgoto

Batch file keeps crashing at if statement


I am making a simple text game. Everything works fine until it gets to the if statement. I do not know what i am doing wrong.

@echo off

title Text Adventures

echo "What is your name?"

set /p name=

echo "That was a bad crash. Are you hurt, %name%?"

echo.

echo Y/N

set /p answer=

if %answer% equ y goto hurt

:hurt

echo.

echo "I see. That's a gnarly gash you've got there!"

Solution

  • I forgot to add pause

    @echo off
    
    title Text Adventures
    
    echo "What is your name?"
    
    set /p name=
    
    echo "That was a bad crash. Are you hurt, %name%?"
    
    echo.
    
    echo Y/N
    
    set /p answer=
    
    if %answer% equ y goto hurt
    
    :hurt
    
    echo.
    
    echo "I see. That's a gnarly gash you've got there!"
    
    pause