Batch file game variable problem

January 4, 2011 at 09:34:08
Specs: Windows XP\Vista
My batch game won't work correctly and I don't know why. If you need me to explain what I am trying to do, just ask. Here is my game code so far.

@echo off
:name
cls
set name=
set /P name=Enter your name.:
echo %name%
echo Is this correct?
set choice=
set /P choice="If it is not press 1 or press 2 to continue:"
if not '%choice%'=='' set choice=%choice:~0,1%
if %choice%'=='1' goto name
if %choice%'=='2' goto start
:start
cls
set one=
set /P one=Enter 1.:
cls
set two=
set /P two=Enter 2.:
cls
echo You are in a room with a door to the North, South, East, and West
set choice=
set /P choice="Press 'n' for North, 's' for South, 'e' for East, and 'w' for West:"
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='n' goto north
if '%choice%'=='s' goto south
if '%choice%'=='e' goto east
if '%choice%'=='w' goto west
:west
cls
echo This room is blocked off
pause
goto start
:east
cls
echo This room is blocked off
pause
goto start
:south
cls
echo This room is blocked off
pause
goto start
:north
cls
echo There is a sword on the ground
set sword=
set /P sword=Pick it up? Press one for yes.:
if '%sword%'='1' sword = %one%
if not '%sword%'='1' sword = %two%
goto battle
:battle
cls
echo You see a giant worm
echo Press enter to fight
pause
cls
if %sword% = %one% goto good
if not %sword% = %one% goto bad
:good
echo it worked
pause
:bad
echo it still worked
pause

Any help?


See More: Batch file game variable problem

Report •

#1
January 4, 2011 at 10:15:16
"My batch game won't work correctly and I don't know why."

Does it give any error(s)?

Place pause between some parts, and check when you getting an error.

Troubleshoot with pauses.

Happy is ONE who says I am an OttoMAN.


Report •

#2
January 5, 2011 at 08:48:16
Okay here is the code section that where the error happens. The error is probably between the REM statements.

echo There is a sword on the ground
set sword=
set /P sword=Pick it up? Press one for yes.:
REM Quits after I enter 1
if '%sword%'='1' sword = %one%
if not '%sword%'='1' sword = %two%
goto battle
:battle
cls
REM it never says any of this
echo You see a giant worm
echo Press enter to fight
pause
cls
if %sword% = %one% goto good
if not %sword% = %one% goto bad
:good
echo it worked
pause
:bad
echo it still worked
pause

Is that any better?


Report •

#3
January 5, 2011 at 09:47:49
"if '%sword%'='1' sword = %one%"

...

if %sword%==1 set sword=1
if not %sword%==1 set sword=2

if %sword%==1 goto GOOD
if not %sword%==1 goto BAD

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

Related Solutions

#4
January 6, 2011 at 12:50:46
Thank you for pointing that out.
I am a retard.

Report •

#5
January 7, 2011 at 00:43:34
You're welcome,

Why you should be a retard? Because you didnt know that?
If it were like that, Einstijn would be a retard too.

Happy is ONE who says I am an OttoMAN.


Report •

#6
January 7, 2011 at 06:35:01
No because I didn't notice that before I posted.

Report •

Ask Question