HeberEbolA
HeberEbolA

Reputation: 1

GOTO and IF statements aren't working correctly

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.

Upvotes: 0

Views: 63

Answers (1)

BDM
BDM

Reputation: 3900

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.

Upvotes: 1

Related Questions