Solved Need to understand the Choice command.

July 15, 2013 at 15:31:27
Specs: Windows xp
How do you use the choice command in a batch file to make your player move around the screen?

I've tried this and it won't work.
@echo off
Set a=X
Set b=0
Set c=0
Set d=0
Echo %a%%d%
Echo %b%%c%
Choice /c "w,a,s,d" /n
If "ERRORLEVEL" ==1 goto room2
If "ERRORLEVEL" ==2 goto room3
If "ERRORLEVEL" ==3 goto room4
If "ERRORLEVEL" ==4 goto room5

The rest is too long to type for me.
So then I would make more rooms and set the "a" "b" "c" and "d" to different numbers so it would look like your moving.

Would this work?

See More: Need to understand the Choice command.

Report •

July 15, 2013 at 19:04:32
✔ Best Answer
"choice" is easy enough: "choice /?" will give you syntax for using the /c option. (hint, it wants a colon, no commas, and no quotes.) As for the other issues, batch is your target of study, and not "choice". I'm sure there's beucoup places to shop for good tutorials, and I can't begin to cover it all. First stop, commandline: FOR /?, SET /?, IF /?.
In this particular instance: If you put quotes around one side of a compare (IF), put quotes around the other side (unless it already has them!)
If you compare system variables, such as errorlevel, you must either leave off the quotes or include the percents. Either way should work. Here's an example of variaous permutations, and also a demo of how to test and debug commands:
::=== begin sample batch

@echo off & setlocal
Set a=X
Set b=0
Set c=0
Set d=0
echo enter 'w', to run tests...
Echo %a%%d%
Echo %b%%c%
Choice /c:wasd /n
echo "errorlevel"
echo "%errorlevel%"
echo %errorlevel%
echo see what i mean?
if %errorlevel%=="1" echo ONE
if %errorlevel%==1 echo ONe
if "%errorlevel%"=="1" echo onE
if %errorlevel% ==1 echo One
if %errorlevel%=="1" echo oNe
::========= end
Ie: if something fails, run tests that display all the variables, exactly as you're using them, and use pauses liberally to separate various displays (sorry if I sound like your sixth-grade math teacher, but debugging is very much in your future if you persist in writing code of any sort). Good luck...

Report •

July 16, 2013 at 03:49:38
You can save much typing and clutter with this:

echo goto :%ERRORLEVEL%

M2 Golden-Triangle

Report •

Related Solutions

Ask Question