This code is designed to resemble a simpler version of the Pokemon battle gameplay. I've only coded in the attacks. I've been testing thoroughly, and found that an error message (Goto was unexpected at this time) whenever the user confirmed their attack. WARNING!! Code is 96 lines long. At the end, I'll put the problem section, so you can skip this first huge chunk.
#echo off
Set H1=20
Set A1=8
Set D1=6
Set S1=5
Set H2=14
Set A2=5
Set D2=4
Set S2=8
:Begin
CLS
Echo Bulbasur
Echo %H2%/14 /\
Echo (__) ___
Echo l __lo.ol
Echo l_\ l_\"
Echo.
Echo _
Echo * / \
Echo \\l )
Echo \\__l Charmander
Echo %H1%/20
Echo -Attack -Capture
Echo -Item -Run
Set /p Move=Action?
If %move%==Attack goto Attack
If %move%==Catpure goto capture
If %move%==Item goto Item
If %move%==Run Goto Run
Echo I'm sorry, Charmander can't do that.
Pause
goto Begin
:Attack
ClS
Echo Attacks
Echo 1)Tackle
Echo 2)Growl
Echo 3)Ember
Echo 4)Scratch
Set /p attack=Which one?
If %attack%==Tackle goto Tackle
If %attack%==1 goto Tackle
If %attack%==Growl Goto Growl
If %attack%==2 goto Growl
If %attack%==Ember goto Ember
If %attack%==3 goto Ember
If %attack%==Scratch goto Scratch
If %attack%==4 goto Scratch
If %attack%==Cancel goto Begin
Echo I didn't get that
Goto Attack
:Tackle
CLS
Echo Tackle Hits The opponent where it hurts. EVERYWHERE.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Tackle
:Growl
CLS
Echo Growl lowers the opponents attack.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Status
If %acccept%==No goto Begin
Echo I didn't get that.
goto Growl
:Scratch
CLS
Echo Scratch hits the foe with a claw.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Scratch
:Ember
CLS
Echo Ember hits the opponent with a small fire.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Ember
:Combat
CLS
If NOT %attack%==Growl If NOT %attack%==2 set /a H2=%H2%-(%A1%^2/%D2%)
set /a H1=%H1%-(%A2%^2/%D1%)
goto Begin
:Status
CLS
Set /a A1=%A1%-1
goto Combat
Problem Area:
:Tackle
CLS
Echo Tackle Hits The opponent where it hurts. EVERYWHERE.
Echo Do you want to?
set /p accept=Yes/No?
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Echo I didn't get that.
goto Tackle
The code gets here fine, but once I'm here, it doesn't expect the goto commands. Anyone can fix this beef? (Note: Tackle is just an example. None of the attacks work.) EDIT: If the user puts in "Yes","No",gibberish, or nothing, it still delivers the same error message (goto was unexpected at this time)
You have to put it in quotes:
if "%accept%"=="yes" goto combat
if "%accept%"=="no" goto begin
Or rather if you dont want to make it case sensitive:
if /i "%accept%"=="yes" goto combat
if /i "%accept%"=="no" goto begin
Your problem is that this line:
set /p accept=Yes/No?
does NOT use the same variable name that these ones:
If %acccept%==Yes goto Combat
If %acccept%==No goto Begin
Above variables have "ccc", but the first one just "cc"
EDIT
Hi, user1205760; I got some time to spend, so I take your program and made it somewhat smaller. This is my version:
#echo off
Setlocal EnableDelayedExpansion
Set Actions=Attack Capture Item Run
Set Attacks=Tackle Growl Ember Scratch Cancel
Set i=0
For %%a in (%Attacks%) do set /A i+=1 & set Attack[!i!]=%%a
Set H1=20
Set A1=8
Set D1=6
Set S1=5
Set H2=14
Set A2=5
Set D2=4
Set S2=8
:Begin
:Cancel
CLS
Echo Bulbasur
Echo %H2%/14 /\
Echo (__) ___
Echo l __lo.ol
Echo l_\ l_\"
Echo.
Echo _
Echo * / \
Echo \\l )
Echo \\__l Charmander
Echo %H1%/20
Echo -Attack -Capture
Echo -Item -Run
Set /p Move=Action?
For %%a in (%Actions%) do if /I %move%==%%a goto %move%
Echo I'm sorry, Charmander can't do that.
Pause
goto Begin
:Attack
Cls
Echo Attacks
For %%a in (1 2 3 4) do echo %%a)!Attack[%%a]!
Set /p attack=Which one?
for %%a in (1 2 3 4) do if %attack%==%%a set attack=!Attack[%%a]!
for %%a in (%Attacks%) do if /I %attack%==%%a goto %attack%
Echo I didn't get that
Pause
Goto Attack
:Tackle
call :Confirm Tackle Hits The opponent where it hurts. EVERYWHERE.
If %accept%==Yes goto Combat
goto Begin
:Growl
call :Confirm Growl lowers the opponents attack.
If %accept%==Yes goto Status
goto Begin
:Ember
call :Confirm Ember hits the opponent with a small fire.
If %accept%==Yes goto Combat
goto Begin
:Scratch
call :Confirm Scratch hits the foe with a claw.
If %accept%==Yes goto Combat
goto Begin
:Status
Set /A A1-=1
:Combat
If /I NOT %attack%==Growl set /A H2=H2-(A1^2/D2)
set /A H1=H1-(A2^2/D1)
goto Begin
:Confirm
Cls
Echo %*
Echo Do you want to?
set /p accept=Yes/No?
For %%a in (Yes No) do if /I %accept%==%%a exit /B
Echo I didn't get that.
Pause
goto Confirm
If the user enters nothing, your If lines probably evaluate to something like this:
…
If ==Yes goto Combat
If ==No goto Begin
…
which is syntactically incorrect. I would suggest initialising accept before the set /p command with some default value:
…
set accept=default
set /p accept=Yes/No?
if …
That way, if the user just hits Enter, the accept variable will retain the default value, and the subsequent if will not end up in the error.
Excuse me,
This is just a question to the downvotes.
The people who asks just IS NOT SURE must the problem be in THAT PART.
e.g.
set a=
if %a%==1 echo yes
If I just post this line:
if %a%==1 echo yes
Then WILL EVERYBODY KNOW WHAT'S THE PROBLEM?
Remember for variable, like %abc%, it's better to use it with ",[ or { so as to prevent error message.
e.g.
set /p abc=
and the user inputs nothing.
Then the next line should be:
if %abc%==1 echo Hi
But it became:
if ==1 echo Hi
,as "%abc%"==""
But with "", it will become
if ""=="1" echo Hi
And "" unequal to "1".
Understand?
EDIT---
If you're using Windows 7 ( or other versions ), you may also try this:
choice /c YN /n /m "Confirm? [Y^|N]
The ^ is just escaping the "pipe" (|).
Hope this will be useful to you!
Related
I'm writing something in BATCH and I need to use GOTO's but instead of going to the correct GOTO it goes to the next label/class rather then the right one.
I've tried using it without a colon but still can't get a solution.
#echo off
title Nexus Generator
color 0a
goto :signin
:signin
echo =====================================
echo Welcome to NEXUS GENERATOR!
echo Please enter your KEY!
echo =====================================
set /p id="Enter Key: "
if %id% == "Test" then goto :signedin else goto :error
:error
echo uh lol
:signedin
cls
echo lol
pause >nul
I expect that when TEST is entered it will go to signedin, and when anything else is entered it will go to error.
You need compare some "in quotes" with some "in quotes" too,
goto :some place to avoid next line to be executed, like goto :eof
#echo off
color 0a
title Nexus Generator
echo/=====================================
echo/Welcome to NEXUS GENERATOR^!
echo/Please enter your KEY^!
echo/=====================================
set /p "id=Enter Key: "
if /i "%id%" == "test" goto :signedin
:error
echo/uh lol
goto :eof
:signedin
cls
echo/lol
pause >nul
in one short version:
#echo off & color 0a
title Nexus Generator
echo/=====================================
echo/Welcome to NEXUS GENERATOR^!
echo/Please enter your KEY^!
echo/=====================================
set /p "id=Enter Key: "
echo/%id%|findstr /lic:"test" 2>nul && goto :signedin
:error
echo/uh lol & goto :eof
:signedin
cls & echo/lol & pause >nul
Seeing as you only have 2 results you want to goto, I would say you do not need the else statement as the goto will only occur if the if statement matches, else it will simply fall through to the error. We however need to test each side of the operator to be equal. Currently you are testing Test == "Test". Note the one is quoted and the other not and you want to have an exact match, therefore you need to double quote your variable. "%id%"=="Test":
#echo off
title Nexus Generator
color 0a
goto :signin
:signin
echo =====================================
echo Welcome to NEXUS GENERATOR!
echo Please enter your KEY!
echo =====================================
set /p id="Enter Key: "
if /i "%id%" == "Test" goto :signedin
echo Oops, you entered "%id%" instead of "Test"
goto :eof
:signedin
cls
echo You're now signed in!!
pause >nul
That said, I prefer not using goto statements unless completely needed, so we can just run code blocks after the if and else statements:
#echo off
title Nexus Generator
color 0a
goto :signin
:signin
echo =====================================
echo Welcome to NEXUS GENERATOR!
echo Please enter your KEY!
echo =====================================
set /p id="Enter Key: "
if /i "%id%" == "Test" (
cls
echo You're now signed in!!
) else (
cls
echo Oops, you entered "%id%" instead of "Test"
)
pause >nul
The game code is pretty simple, the code for it is below. Can't figure out why syntax for :WRONG section is well wrong. I've tried mirroring it exactly from the start section which works and is identical. Anyone offer any input?
color 4a
cls
:MAIN
#echo off
echo Welcome to XXXX's Trivia Game!!
pause & echo Ready to start?
set /p input=(Y/N)
if %input%==y goto SECTION1
goto BYE
:BYE
#echo Sorry to see you leave! Have a nice day!
pause
exit
:SECTION1
#echo FIRST QUESTION!!!!
pause
cls & echo At what temperature does rain turn to snow?
echo A. 112 degrees
echo B. -37 degrees
echo C. 32 degrees
echo D. 17,341 degrees
set /p input=Answer?
if %input%==C goto 2
goto WRONG
:SECTION2
:SECTION3
:SECTION4
:SECTION5
:SECTION6
:SECTION7
:SECTION8
:SECTION9
:SECTION10
:WRONG
cls & echo You were wrong, would you like to start again?
set /p input==(Y/N)
if %input%==y goto :SECTION1
goto BYE
pause
:HALFWAY
:WIN
Things I've tried:
Removing all sections between :SECTION1 and :WRONG
Renaming :WRONG and the call for it in :SECTION1
Removing :HALFWAY and :WIN
Copying from :MAIN (working correctly) to :WRONG (still no dice)
The following command has an extra = that causes a syntax error:
set /p input==(Y/N)
The prompt for set /p cannot begin with =. Remove the unwanted char as follows, and the command will work.
set /p input=(Y/N)
You are reusing the input variable, and set /p will preserve any pre-existing value if the user simply presses <Enter>. You should clear the value before prompting for input.
set "input="
set /p input=(Y/N)
There are lots of additional areas where your code could (should) be improved, but I will let you discover them at your own pace.
A basic yes/no choice command example for you:
#Choice /M "Ready to start?"
#Echo=%%ERRORLEVEL%% is %ERRORLEVEL%
#Timeout 5
Run it and see what happens when you enter different options.
Fixed your game :)
Try the below code...
Edit: Did some code improvements and cleanup, hope you'd like it...
#echo off
color 4a
cls
:MAIN
cls
echo.
echo --------------------------------------
echo Welcome to New-B-Admin's Trivia Game!!
echo --------------------------------------
echo.
set /p input="Ready to start playing ? Answer (Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto MAIN
:SECTION1
cls
echo ------------------
echo Question Number 1
echo ------------------
echo.
echo At what temperature does rain turn to snow?
echo.
echo A. 112 degrees
echo B. -37 degrees
echo C. 32 degrees
echo D. 17,341 degrees
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="c" (
call :CORRECT
goto SECTION2
)
if /i "%input%"=="d" goto WRONG
::the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION1 rem rename this goto statment to the same name as the label.
:SECTION2
cls
echo ------------------
echo Question Number 2
echo ------------------
echo.
echo What year was the two dollar bill last printed in the United States?
echo.
echo A. 1997
echo B. 2001
echo C. 2003
echo D. 2007
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="c" (
call :CORRECT
goto SECTION3
)
if /i "%input%"=="d" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION2 rem rename this goto statment to the same name as the label.
:SECTION3
cls
echo ------------------
echo Question Number 3
echo ------------------
echo.
echo How many super bowls have the Denver Broncos won?
echo.
echo A. 5
echo B. 10
echo C. 7
echo D. 3
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="d" (
call :CORRECT
goto SECTION4
)
if /i "%input%"=="c" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION3 rem rename this goto statment to the same name as the label.
:SECTION4
cls
echo ------------------
echo Question Number 4
echo ------------------
echo.
echo What was the name of the hourse from The Lone Ranger Movie that he saved from an enraged buffalo?
echo.
echo A. Silver
echo B. Yellow
echo C. White
echo D. Buck
echo.
set /p input="Your answer?: "
if /i "%input%"=="c" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="a" (
call :CORRECT
goto SECTION5
)
if /i "%input%"=="d" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION4 rem rename this goto statment to the same name as the label.
:SECTION5
:SECTION6
:SECTION7
:SECTION8
:SECTION9
:SECTION10
:END
cls
echo.
echo --------------------
echo No more questions!!!
echo --------------------
echo.
set /p input="Would you like to restart the game ? Answer (Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto END
:WRONG
cls
echo.
set /p input="You were wrong, would you like to start again?(Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto WRONG
:CORRECT
cls
set input=0
echo.
echo Correct!!! Great progress :)
echo Press enter to continue to next question...
pause >nul
goto :EOF
:HALFWAY
:WIN
:BYE
cls
echo.
echo ----------------------------------------
echo Sorry to see you leave! Have a nice day!
echo ----------------------------------------
pause >nul
exit
I am making a batch file, and whenever their is a user input field, which the user enter a word or a sentence and it get stored in a text file. I made all the job done.
But when the user's input is more than 1 word, it gives the following error:
*second word* was unexpected.
How can this be solved?
#echo off
color f0
:menu
cls
echo Batch Editor
echo Choose what you want to do:
echo 1) New Document
echo 2) Load existing document
echo 3) Learn How to Use
echo 4) Exit
set /p menu=
if %menu%==1 goto new
if %menu%==2 goto load
if %menu%==3 goto learn
if %menu%==4 goto exit
if [%1]==[] goto learn
echo Invaild Code
pause
goto menu
:new
cls
echo You have chosen to start a new document.
echo But please note that is impossible to know how to code
echo without seeing the "How to Learn" section.
echo Choose:
echo 1) Continue anyways
echo 2) Go to the "How to Learn" section
echo 3) Exit
set /p type=
if '%type%'=='' goto new
if %type%==1 goto newdoc
if %type%==2 goto learn
if %type%==3 goto exit
echo Invaild Key
pause
goto new
:newdoc
cls
set /p input=
if %input%==Qsave goto saving
if %input%==qsave goto saving
if %input%==qSave goto saving
if %input%==QSAVE goto saving
goto newdoc1
pause
:newdoc1
set /p chosen=
if '%chosen%'==''(
goto newdoc2)
else if "%chosen%"=="Qsave" (
goto saving)
else if "%chosen%"=="qsave" (
goto saving)
else if "%chosen%"=="qSave" (
goto saving)
else if "%chosen%"=="QSAVE" (
goto saving)
else (
goto newdoc2)
:newdoc2
set /p chosen=
if '%chosen%'==''(
goto newdoc1)
else if %chosen%==Qsave (
goto saving)
else if %chosen%==qsave (
goto saving)
else if %chosen%==qSave (
goto saving)
else if %chosen%==QSAVE (
goto saving)
else (
goto newdoc1)
:saving
cls
echo Saving
pause
:load
echo LOADING
pause
:learn
echo Learn
pause
:exit
cls
set /a exiting=0
echo Are you sure you want to exit?
echo Choose:
echo 1)Exit
echo 2)Go Back to the Main Menu
set /p exiting=
if %exiting%==1 exit
if %exiting%==2 goto menu
echo Invaild key
pause
goto exit
pause
exit
You really should post what you currently have, if all you're trying to do is store user inputted text to a text file, something like this might help?
SET /P Answer=Say somthing witty!
ECHO %Answer%>Response.txt
set var=Alpha beta Gamma
if %var%==whatever
is translated to:
if Alpha beta Gamma==whatever
IF Syntax is IF <Argument1> <comparator> <Argument2> <command>
Argument1 is Alpha, Comparator is beta - wait, this is wrong...
It leads to "beta was unexpected", because there should be a compatator (==), not an Argument.
Better Syntax:
if "%var%"=="whatever"
is translated to:
if "Alpha beta Gamma"=="whatever"
Argument1 is "Alpha beta Gamma", Comparator is ==, Agrument2 is "whatever" - fine Syntax.
Sample menu where there are only three possible choices plus one covering mistype:
#echo off
:retry
cls
Unset the variable M
set M=
If nothing typed, then set M to 4
SET /P "M=Type 1 for pizza, 2 for soup or 3 for exit, then press ENTER: " || set "M=4"
Here we use variable substring. See http://ss64.com/nt/syntax-substring.html
IF [%M:~0,1%]==[1] goto pizza
If M are not set to 1, then go to the next line, etc...
IF [%M:~0,1%]==[2] goto soup
If M are not set to 1 or 2 then check if it's set to 3, there is the last IF statement, we can now use else to cover everything else in the variable M
IF [%M:~0,1%]==[3] (
echo Bye...
#timeout /T 1 /nobreak >NUL
exit /b 0
) else (
goto :retry
)
:pizza
echo Pizza
goto :EOF
:soup
echo Soup
goto :EOF
Edit: My if statement was a bit redundant, see the revision history to see what I mean.
This question already has an answer here:
set /p empty answer crash
(1 answer)
Closed 7 years ago.
So, I am asking the user to make an selection. The point of this question is to catch if the user hit just entered without any input. My plan is to find out if the user entered nothing and just hit entered. If so, then display that it is not a valid option and go back to :START. The following code does not work - especially the empty input and the input with just space character. If the user did this invalid thing then I just want to display the message saying it is empty.
Any suggestions on how to handle this issue would be greatly appreciate.
#echo off
:START
cls
echo Choose your option & echo.
echo [P] play
echo [R] rules
echo [M] main menu
echo [E] exit
set /p "cho=->"
if %cho%==e (goto EXIT
) else if /I %cho%==m (goto MAINMENU
) else if /I %cho%==r (goto GAMERULES
) else if /I %cho%==p (goto GAMERULES
) else if %cho%=="" (goto EMPTYINPUT
) else if %cho%==" " (goto EMPTYINPUT
) else cls
echo That is not valid
pause
:EMPTYINPUT
echo This is not a valid option.
pause
goto START
You may avoid all the option identification problems if you use choice instead set /P. Choice command will respond just to a limited set of keys defined by you, so its answer is always correct.
#echo off
:START
cls
echo Choose your option & echo.
echo [P] play
echo [R] rules
echo [M] main menu
echo [E] exit
choice /C PRME /N /M "->"
goto option-%errorlevel%
:option-1 PLAY
echo In play
pause
goto start
:option-2 GAMERULES
echo In game rules
pause
goto start
:option-3 MAINMENU
echo In main menu
pause
goto start
:option-4 EXIT
echo Bye...
goto :EOF
For further details, type: choice /?
You can also try it with a dynamic menu like this :
#echo off
Mode con cols=90 lines=15
:menuLOOP
Mode con cols=70 lines=15
Cls & color 0B
Title Example of Dynamic Menu
echo(
echo( ============================Menu===========================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo( %%A %%B
echo(
echo( ============================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
:menu_[P] PLAY
cls & Color 0A
echo.
echo In play
pause
GOTO:menuLOOP
:menu_[G] GAMERULES
cls & Color 0C
echo.
echo In game rules
pause
GOTO:menuLOOP
:menu_[M] MAINMENU
cls & Color 0D
echo.
echo In main menu
pause
GOTO:menuLOOP
:menu_[E] EXIT
echo Bye...
Exit
Every time I try playing it exits instead of moving on to the next line when I clik enter; it works fine until after you enter your name, then it skips to question 1, then it exits. I'm not an expert on this so I would like to know what I'm doing wrong and how to fix it. If you notice any other mistakes please feel free to point them out. Thanks! :)
#echo off
color F0
cls
echo.
echo True or False
pause
echo Welcome! May I ask your name before we begin?
echo.
set /p name=
echo.
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.
cls
echo.
echo Let us begin!
:start
color FC
cls
echo.
echo QUESTION 1
pause
echo.
echo Though hard, you can start a fire by rubbing 2 cool ranch
doritos together for a long time.
echo.
echo TRUE or FALSE
echo.
set /p variable=
echo.
if %variable% equ TRUE goto question2 if %variable% equ FALSE goto
answer1
if %variable% neq TRUE goto start
:answer1
cls
echo.
echo Wrong! Though it is very hard, it is possible.
goto start
:question2
color F3
cls
echo QUESTION 2
pause
echo.
echo Singing in the shower lowers your cholesterol, heart rate, &
risk of cancer and heart disease.
echo.
echo TRUE or FALSE
echo.
set /p variable=
echo.
if %variable% equ TRUE goto answer2
if %variable% equ FALSE goto question3
if %variable% neq TRUE goto question2
:answer2
cls
echo.
echo Wrong!
echo.
echo Here is a fast fact for you %name%. Dark chocolate doesn't
either.
goto start
:question3
color F5
cls
echo QUESTION 3
pause
echo.
exit
You had some syntax errors and various issues. Try this as an example: it has some changes and edits to make it more robust.
#echo off
color F0
cls
echo.
echo True or False
echo.
set /p "name=Welcome! May I ask your name before we begin? "
echo.
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.
echo.
ping -n 3 localhost >nul
echo Let us begin!
pause
:start
color FC
cls
echo.
echo QUESTION 1
echo.
echo Though hard, you can start a fire by rubbing 2 cool ranch
echo doritos together for a long time.
echo.
echo.
set /p "variable=TRUE or FALSE: "
echo.
if /i "%variable%" equ "TRUE" (
echo Right!
pause
goto :question2
)
cls
echo.
echo Wrong! Though it is very hard, it is possible.
pause
:question2
color F3
cls
echo QUESTION 2
echo.
echo Singing in the shower lowers your cholesterol, heart rate, &
echo risk of cancer and heart disease.
echo.
set /p "variable=TRUE or FALSE: "
echo.
if /i "%variable%" equ "FALSE" (
echo Right!
pause
goto :question3
)
echo
cls
echo.
echo Wrong!
echo.
echo Here is a fast fact for you %name%. Dark chocolate doesn't
echo either.
pause
:question3
color F5
cls
echo QUESTION 3
pause
echo.
exit
Try this:
if "%variable%" equ "TRUE" goto :question2
if "%variable%" equ "FALSE" goto :answer1
goto :start
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.
cls
echo.
echo Let us begin!
The CLS command makes to clean the window, so you can read nothing. Also you need to stop the execution of the script (with a pause).
You are using the cls command too many times without pausing the code.
Also you need to try to don't make a intelligible code like that, you need to make indentations, make empty lines, to let us understand the code.
And no need to use string recognitions like "true or false?" because exist a type of variable called "Boolean" and that is only True/False, you can use boolean questions with the Choice command.
Really you need to rewrite it all the code again because you can see things like this:
if %variable% equ TRUE goto answer2
if %variable% equ FALSE goto question3
if %variable% neq TRUE goto question2
if variable only can be "true" and "False" then the third conditional never will be processed, no need to be a pro to understand it, is logical.
And think about what happens if the user type "true" or "TrUe" or any variant?
Then you will need to use the /I parameter of "IF" statement.
If /I EQU "True" (Goto...) ELSE (Goto...)
And you are using the operator "&" to print a string using echo command, but you can't print operators without using double-quoues or escaping the character:
Echo "&"
Echo ^&
Too many thing more for explain but the big problem of your code is that you've missed like 10 "pause" needed to read the strings.
PS: Sorry for my english.
Here is the corrected code:
#Echo off
Color F0
Echo+
Echo: True or False | MORE
Pause & CLS
Echo+
Echo: Welcome! May I ask your name before we begin? | MORE
set /p "name=" & CLS
Echo+
Echo: Hello %name%, nice to meet you! | MORE
Echo: My name is Myst. | MORE
Pause & CLS
Echo+
Echo: Let us begin!
Pause & CLS
:start
color FC
Echo+
Echo: QUESTION 1
Pause
Echo+
Echo: TRUE or FALSE | MORE
Choice /C TF /M "Though hard, you can start a fire by rubbing 2 cool ranch doritos together for a long time."
if %ERRORLEVEL% EQU 1 (Goto Question2) ELSE (goto Answer1)
:answer1
cls
Echo+
Echo: Wrong! Though it is very hard, it is possible.
Pause & CLS
Goto :start
:question2
color F3
cls
Echo: QUESTION 2
pause
Echo+
Echo: TRUE or FALSE | MORE
Choice /C TF /M "Singing in the shower lowers your cholesterol, heart rate, & risk of cancer and heart disease."
if %ERRORLEVEL% EQU 1 (Goto answer2) ELSE (goto question3)
:answer2
cls
Echo+
Echo: Wrong! | MORE
Echo: Here is a fast fact for you %name%. Dark chocolate doesn't either.
Pause & CLS
goto start
:question3
...
...
...