Checking Blank User Input in Batch file (No Input) [duplicate] - windows

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

Related

Batch program is skipping GOTO blocks

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

Batch: simple game syntax is wrong, can't figure out why?

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

Trying to make a telefphonebook in batchscript Win8

I'm a beginner to batchscripting and I'm trying to make a telephoneregister that prints all, adds, deletes and searches for phonenumbers, but I can't get it to work correctly and I'm wondering where I did go wrong. The code is down below, thanks in advance.
echo Print out all content ^<1^>
echo Add a new number ^<2^>
echo Delete a number ^<3^>
echo Search ^<4^>
echo Exit ^<5^>
set /p val="Choose between 1-5: "
GOTO CASE_%val%
:CASE_1 for /f "tokens=*" %%a in
(telephoneregister.txt) do
( echo %%a )
GOTO END_SWITCH
:CASE_2 echo "Number: " set /p p1="Nr"
echo %p1% >> %output%\telephoneregister.txt
GOTO END_SWITCH
:CASE_3 echo "Which number would you like to delete? "
set /p num="Telephoneregister"
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt
type telephoneregister.txt > tele.txt del /s tele1.txt
GOTO END_SWITCH
:CASE_4 set /p n1="Number: "
findstr %n1% telephoneregister.txt
GOTO END_SWITCH
:CASE_5 exit 0
GOTO END_SWITCH
:END_SWITCH
pause
I got to this code here:
#echo off
:menu
cls
echo 1- Print out all content
echo 2- Add a new number
echo 3- Delete a number
echo 4- Search
echo 5- Exit
set /p val="Choose between 1-5: "
if %val%== 1 goto one
if %val%== 2 goto two
if %val%==3 goto three
if %val%== 4 goto four
if %val%== 5 goto five
:one
cls
type telephoneregister.txt
echo.
echo ====================
set /p =ENTER to go back to menu.
goto menu
:two
cls
set /p p1="Number: "
echo %p1% >> telephoneregister.txt
echo.
echo ====================
set /p =ENTER to go back to menu.
goto menu
:three
cls
echo Which number would you like to delete?
set /p num="Telephoneregister: "
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt
type telephoneregister.txt > tele.txt del /s tele1.txt
set /p =ENTER to go back to menu.
goto menu
:four
cls
set /p n1="Number: "
findstr /r /c:%n1% telephoneregister.txt
echo.
echo ====================
SET /p =ENTER to go back to menu.
goto menu
:five
exit
It's not completely done yet (Option 3 It's not working) but you can see what you had wrong, and probably come to the solution searching on the web. If you have any question in the code above, Just ask! Good luck.

Batch game exits instead of going to next line

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
...
...
...

Goto was unexpected at this time batch windows 7 starter

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!

Resources