Can someone fix this? After I start, if I type in no command, it shuts off. Same with the examine commands...
@echo off goto :Start set area = 00 set inventory = :Start echo. echo. title Sep's First DOS-Game! echo Welcome to the epic DOS game! echo 1) Play echo 2) Quit echo 3) Help set /p mainchoice= if %mainchoice%==1 goto :00 if %mainchoice%==2 exit if %mainchoice%==3 goto :Help :Help echo. echo. echo Type in the commands you would like to use when you are prompted. echo. echo Commands: echo use echo use ____ with ____ echo look echo examine ____ echo inventory echo. pause goto :Start :00 set area = 00 echo. echo. echo You awake in a blank room... set /p do=What would you like to do?: if %do% == look goto (:Look00) else if %do% == use lightbulb () else if %do% == inventory (echo. echo. echo You have %inventory% in your inventory. goto :00) else if %do% == examine walls (echo. echo. echo Blank, white walls. This one has a small hole in it. goto :00) else (goto :00) :Look00 echo. echo. echo You are in a blank, white room, with blank walls, a blank floor, and a small lightbulb on the ceiling. goto :00
Offline
You cannot use replies with 2 words. It confuses the DOS prompt, and shuts it down.
Offline
OK, here are a few tips to fix up your code:
1. Drop the spaces on both sides of the equals sign when using the set command. Change "set area = 00" to "set area=00", etc.
2. Put double quotes around variables and what they are compared to when using "==". For example, change '%do%==examine walls' to '"%do%"=="examine walls"'. This will allow you to use spaces when using "set /p".
3. When you have multiple-choice inputs with only one character for each, use the "choice" command instead of "set /p" and use "if ERRORLEVEL x" commands to filter the results. Changing your "Play, Quit, Help" choice to this would look like this:
choice /c 123 /n if ERRORLEVEL 1 goto :00 if ERRORLEVEL 2 exit /b ::oh BTW, use "exit /b" when exiting so it will exit the batch file ::but not the command prompt if the batch file is run from the prompt. if ERRORLEVEL 3 goto :Help
More info on the choice command here.
4. Your "if else" syntax looks messy. Here's an example to look off of:
if %var%==something ( echo. echo The variable "var" is "something"! echo. ) else ( echo. echo The variable "var" is not "something"! echo. )
Also, put spaces between parentheses and the command directly before/after them.
Offline
While testing:
Welcome to the epic DOS game! 1) Play 2) Quit 3) Help f Type in the commands you would like to use when you are prompted. Commands: use use ____ with ____ look examine ____ inventory Press any key to continue . . . Welcome to the epic DOS game! 1) Play 2) Quit 3) Help 1 You awake in a blank room... What would you like to do?: look You are in a blank, white room, with blank walls, a blank floor, and a small lig htbulb on the ceiling. You awake in a blank room... What would you like to do?: examine wall 'else' is not recognized as an internal or external command, operable program or batch file. 'else' is not recognized as an internal or external command, operable program or batch file. You have in your inventory. You awake in a blank room... What would you like to do?:
It doesn't understand else...
Offline
OK, so I have this:
@echo off
set area=00
set inventory=
goto :Title
:Title
echo \ \ / / __ ___ _ ___ _
echo \ \/ / /__ | |_) |__ /_\ /\ /\
echo / /\ \ __/ | | \ |___ / \ / \/ \
echo / / \ \ Games
echo It's not extreme, it's XStream.
echo.
echo Press any key to start...
pause
goto:Start
:Start
echo.
echo.
title Sep's First DOS-Game!
echo Welcome to the epic DOS game!
echo 1) Play
echo 2) Quit
echo 3) Help
set /p mainchoice=
if %mainchoice%==1 goto :00
if %mainchoice%==2 exit
if %mainchoice%==3 goto :Help
:Help
echo.
echo.
echo Type in the commands you would like to use when you are prompted.
echo.
echo Commands:
echo use ____ -- Use the item. It doesn't need to be in your inventory.
echo use ____ with ____ -- Combine two items, or use an item on another.
echo look -- Look around the current room.
echo examine ____ -- Look carefully at an item.
echo inventory -- Check your inventory.
echo.
pause
goto :Start
:00
set area = 00
echo.
echo.
echo You awake in a blank room...
set /p do=What would you like to do?:
if "%do%"=="look" (
goto :Look00
) ELSE (
if "%do%"=="use lightbulb" (
echo.
echo.
echo You can't reach it.
goto :00
) ELSE (
if "%do%"=="inventory" (
echo.
echo.
echo You have %inventory% in your inventory.
goto :00
) ELSE (
if "%do%"=="examine walls" (
echo.
echo.
echo Blank, white walls. This one has a small hole in it.
goto :00
) ELSE (
if "%do%"=="examine wall" (
echo.
echo.
echo Blank, white walls. This one has a small hole in it.
goto :00
) ELSE (
goto :00
)
)
)
)
)
:Look00
echo.
echo.
echo You are in a blank, white room, with blank walls, a blank floor, and a small lightbulb on the ceiling.
goto :00But when I start it, it shuts right away... It started after I added the title part, with the XStream games...
Offline
OK, here's a way that will work, but it involves writing to files.
I'm assuming that you want to filter user input.
::This writes the user input to a file echo %choice% > $][gametmp.tmp find %textyouwanttofindhere%<$][gametmp.tmp>nul
We have to write the user input to a file because the FIND command refuses to search in a string. After the FIND command, use "if ERRORLEVEL n" to detect if the user input contains something; if the input does contain something, the command returns 0, and if it doesn't, it returns 1. You can delete the temporary file after you run the command.
Offline
In this case, you would do "del $][gametmp.tmp".
Offline