Saspurilla
Saspurilla

Reputation: 11

Can't find syntax error in batch file

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!

Upvotes: 1

Views: 1154

Answers (3)

J03L
J03L

Reputation: 324

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.

Upvotes: 1

FloatingKiwi
FloatingKiwi

Reputation: 4506

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 
    

Upvotes: 3

Mike Nakis
Mike Nakis

Reputation: 62179

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.

Upvotes: 1

Related Questions