0

I have a batch-game where there's some questions for one person in particular, I always change the file when she(the person) isn't nearby so its kind of a surprise. The thing is I keep on displaying questions of different types but sometimes the GOTO or IF statements just simply doesn't work properly, it just follow the line or exit the file.

@ECHO OFF
setlocal EnableDelayedExpansion
ECHO.
ECHO "i just skipped all this echo for you"
pause>nul
:choice
cls
set /p c=Question 1[y/n]
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice

:somewhere
cls
cd "-somewhere in my pc-"
start "-the file-"
cls
goto :somewhere1

:somewhere1
cls
echo.
echo "skip"
pause>NUL
goto :somewhere2

:somewhere2
cls
echo.
set /p c1=question 2
if /I "!c1!"== "option1" goto :correct 
if not /I "!c1!"== "option1" goto :somewhere_else1

:correct
cls
echo.
echo "skip"
echo.
echo enter to exit
pause>nul
exit

:somewhere_else1
cls
echo.
echo bad answer
pause>nul
goto :somewhere2

Here are my problems:

When it ask's you the question

:choice
cls
set /p c=Question 1[y/n]
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice

it's just work properly, it wasn't working in the past but I magically fixed it with no idea what i'm doing. but then I just wanted to make it bigger and add the next lines:

:somewhere2
cls
echo.
set /p c1=question 2
if /I "!c1!"== "option1" goto :correct 
if not /I "!c1!"== "option1" goto :somewhere_else1

and now the file is executing perfectly the ":correct" part but no the ":somewhere_else1". in the case of ":somewhere_else1" its just exit the file. in the past was exiting the file the right one too but again I fixed it just writing it again.

Omkar C.
  • 755
  • 8
  • 21
  • 1
    See answer on [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) It explains very detailed why `set /P` should not be used for a choice menu. There is the command `choice` for such tasks. See also DosTips forum topic [ECHO. FAILS to give text or blank line - Instead use ECHO/](https://www.dostips.com/forum/viewtopic.php?f=3&t=774) explaining wny `echo/` or `echo(` is better than `echo.` to output an empty line. – Mofi Sep 05 '19 at 05:37

1 Answers1

1

The problem is your line if not /I "!c1!"== "option1" goto :somewhere_else1

The /I needs to be before not

if /I not "!c1!"== "option1" goto :somewhere_else1

Though I should also mention that your use of ! instead of % is unnecessary in this example.

You should have a read through this link to get some insight into how to fix these errors yourself in the future, and perhaps this link on good practice.

BDM
  • 3,760
  • 3
  • 19
  • 27
  • Thank you very much, It worked as It should, I would say its magic but its knowledge. Hope can give you back the help some day. – HeberEbolA Sep 08 '19 at 05:50