batch-file


windows batch file - IF with AND condition using command-line arguments with a multi-line body [duplicate]


i am new here so i'll try to be as good as i can.
So i am trying to make a RPG based on text-based MS-DOS, and i am going pretty well as i just saw that if the user puts an invalid input at set /p, like an empty answer (just pressing enter) or an answer which is not on the "IF", the batch just crashes, and I would like to fix that so it will be less crashy.
Here is one of the parts i'd like to fix:
#echo off
title "Wasteland Adventure"
color 0A
cls
:Menu
cls
echo.
echo.
echo Welcome to Wasteland Adventure
echo.
echo To start a new game, type NEW and press ENTER.
echo To see instructions for the game, type INSTRUCTIONS and press ENTER.
echo To quit, type QUIT and press ENTER.
set input=
set /p input=What do you want to do?
if %input%==new goto INTRO
if %input%==instructions goto INSTRUCTIONS
if %input%==quit goto EXIT
Thanks in advance
it's not the set /pthat crashes, but:
if %input%==new
if %input% is empty, this is parsed as:
if ==new
obviously a syntax error. To avoid this, use:
if "%input%"=="new"
An empty input will then be parsed as:
if ""=="new"
which works fine. Complete code like this:
:Menu
set input=
set /p input=What do you want to do?
if "%input%"=="new" goto INTRO
if "%input%"=="instructions" goto INSTRUCTIONS
if "%input%"=="quit" goto EXIT
REM for any other (invalid) input:
goto :Menu

Related Links

“The system couldn't find the path specified” batch file error
How to create an Admin shortcut with NSIS?
batch to rename multiple files
Usage Of && and ||
Batch + powershell script renamer wrong directory error
Copy several files into one if they exist
What's Wrong With My Batch File
how to use a variable (read from a file) for url in curl using batch script for windows?
Executing Variable With Space In Path
Batch file REG QUERY command searches in 32 bit registry instead of 64 bit
Pausing a batch file as it is running
How to run .clp file in jess
XP To Windows 7 - Command Batch Script In Context Menu not working! Any Help Greatful
Rename text files based on multiple strings in their contents
How do I properly make my batch game self check for updates on other people's computers and download them if needed?
batch file delayed expansion line by line file copy that contains exclamation points

Categories

HOME
phpword
turing-machines
cobalt
codenvy
jax-rs
themes
can
alsa
vxml
square
pearson-correlation
nuget-package
mvc5
barcode
spin
categorical-data
minecraft-forge
google-chrome-app
github-enterprise
filechannel
php-5.6
mongodb-csharp
capistrano3
coin3d
fileserver
forgot-password
git-extensions
microsoft-ocr
asciidoctor-pdf
jquery-ias
parcelable
epsilon
android-sharedpreferences
licensing
soot
finagle
complex-numbers
testbed
android-maps-extensions
sendbird
reason
zoomify
graphhopper
dm-script
timing
filesystemwatcher
mcustomscrollbar
comparison-operators
print-css
http-request
knime
android-exoplayer
pom.xml
mesosphere
fwrite
cnc
robomongo
corruption
pair-programming
static-cast
wpas
gameplay-kit
baidu
rmongo
atlas
builtins
parfor
tooleap
omniauth-facebook
tracker-enabled-dbcontext
spreadjs
pushbots
realsense
assertion
sha512
umlgraph
cross-join
document-repository
tweenlite
jama
raygun
gii
dot42
spring-3
gtm-oauth2
inputmismatchexception
away3d
cocoalibspotify-2.0
inappsettingskit
beaker-testing
swfobject
redis-py
pyunit
thttpd
oracle-enterprise-linux
ilasm
gobject-introspection
android-holo-everywhere
entitydatasource
dataform
http-daemon
object-database
jqueryform
burndowncharts
tui
visualj#
entitykey
soappy
information-management
lemmatization

Resources

Encrypt Message