1

So I'm relatively new to coding, and I just can't seem to find the syntax error in this code of mine. Every time the menu loads, and I press 1, it closes and flashes a quick error saying that there is a syantax error. If you guys could help me find out what's causing the problem. BTW, this is a text based rpg. No judge :)

@echo off
TITLE VICTIMQUEST =-= RETRO EDITION
setlocal enabledelayedexpansion

:menu
color 0a
cls
echo.
echo VICTIMQUEST =-= RETRO EDITION
echo.
echo 1) Begin
echo 2) Exit
echo.
set /p c=C:\

if "%c%" == "1" goto new
if "%c%" == "2" exit
goto menu

:new
set health=100
set monsterhealth=30
set playerdmg=7
set monsterdmg=3
goto home

:home
cls
echo You sit in your nice, cozy cabin...
echo ----------------------
echo Nothing you need to worry about.
echo.
echo 1) FIGHT!
echo 2) Quit :|
echo.
set /p c=C:\

if "%c%" == "1" goto encounter1
if "%c%" == "2" goto menu
goto home

:encounter1
cls
echo You: %health%
echo.
echo 1) Attack
echo 2) Run away
echo.
set /p c=C:\

if "!c!" == "1' goto attack1
if "!c!' == "2" goto home
goto encounter1

Please help. Thanks!

1
  • 3
    1. If you open a Command Prompt window and run your script from there, you'll see the exact error message without the console window disappearing on you. (If you temporarily remove the @echo off line, you should see where the problem is too.) 2. Trying to write non-trivial code as a .bat/.cmd script is asking for pain. Why don't you learn a nice scripting language like Python instead? Commented Sep 27, 2016 at 23:29

3 Answers 3

3

3 Changes:

  1. REM @echo off - Echo should be on when you are debugging or you're flying blind
  2. The pipe character | is a special character and must be escaped with ^.

    echo 2) Quit :^|
    
  3. Incorrect quote mark. Needs to be a double quote.

    if "!c!" == "1" goto attack1 
    
Sign up to request clarification or add additional context in comments.

Comments

1

I should warn you that computers are extremely picky when it comes to punctuation.

Things like "!c!" == "1' and "!c!' == "2" will never work.

The | character has a special meaning, so you cannot use it unless you escape it with a ^ or you place it in double quotes together with other stuff.

Comments

1

add

pause >nul

to the end of your batch file. this will make it so the batch file will not close until the user presses a key.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.