0

I'm making a text adventure in Batch and I was wondering why when I go to a level, the Window closes. Here's (some) of the code:

Level Code:

:C11x0y0
cls
title Level C11x0y0
echo -Info-
echo Coordinates: x0, y0
echo No Treasure
if %cheat% = 1 echo CHEAT gem x1 y0 exit x-1 y1
echo -Keys-
echo a - move left
echo s - move backwards
echo w - move forwards
echo d - move right
set /p direction=

if %direction% == a goto C11x-1y0
if %direction% == s goto C11x0y-1
if %direction% == w goto C11x0y1
if %direction% == d goto C11x1y0

Menu Code:

title Cave Advnture - Easy
cls
echo 1: Level 1
echo 2: Level 2
set /p choice=

if %choice% == 1 goto C12x0y0
if %choice% == 2 goto C11x0y0

Notes:

Level 2 works, that's a good sign, so I'll compare and contrast there.

  • 1
    Without your complete batch file we would only be guessing. Please read Debugging your batch files – DavidPostill Jan 14 '18 at 19:57
  • Your link is broken or misspelled. – Ryan Jan 14 '18 at 20:47
  • Ah. https thing. fixed. – DavidPostill Jan 14 '18 at 20:48
  • I already spotted an error, that might be your problem. if %cheat% = 1 echo CHEAT gem x1 y0 exit x-1 y1 has only 1 = for the if. Batch need 2 ==. Also, run the batch file from a command prompt so it will show you an error instead of a vanishing window (which shows an error and directly after closes) – LPChip Jan 14 '18 at 20:57
  • I've posted an answer. If it indeed solved your problem, please mark it as answered, so others know you no longer need help. If not, please post your entire batch file. – LPChip Jan 14 '18 at 21:38
0

I already spotted an error, that might be your problem.

if %cheat% = 1 echo CHEAT gem x1 y0 exit x-1 y1 

This line has only 1 = for the if. Batch need 2 ==.

Also, run the batch file from a command prompt so it will show you an error instead of a vanishing window (which shows an error and directly after closes)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.