0
\$\begingroup\$
@echo off

:An
@echo Everything has a start...
SET /P _inputname= Please enter your character's name:
SET /P _inputgen= Please enter your character's sex:
set /A hp=10
pause
cls
@echo Your name is %_inputname%
@echo You are a teenage %_inputgen%
pause
cls
@echo This story starts here...
pause
cls
@echo You wake up alone in your room, it's still dark.
@echo 1: Get out of bed
@echo 2: Try to sleep
SET /P _1Dec= What you want to do?
cls
if %_1Dec%==1 (
@echo Now you finally got up. You turned the light on. The first thing you saw was a blinding flash of light.
) else (
@echo You lazily closed your eyes again. It's not morning right now. Why would you get up so early. You managed to fall asleep again easily...
@echo When you finally get up, it's already morning and you can feel all the light even through your closed eyes.But you feel rested and in better mood
set /A hp=%hp%+1
)
@echo Your health: %hp%
pause
cls
@echo Now you can see. But there's one problem. You don't like what you see.
@echo Your mom once said, that you have the most untidy room on the whole world.
@echo But nevermind your mom. The room is quite big, but most of the place is taken by your table, bed and a gigantic wardrobe.
@echo 1: Search around a bit
if %_1Dec%==1 (
@echo 3: Get some sleep
@echo Your health: %hp%
SET /P _2Dec= What do you want to do?
) else (
@echo 2: Go out of your room
@echo Your health: %hp%
SET /P _2Dec= What do you want to do?
)
if %_2Dec%==1 (
@echo First you open your wardrobe. 
@echo The first thing you notice (apart from the incredible mess) is a little silver flashlight, currently turned on.
@echo 1: Take it
@echo 2: Let it here
SET /P _2.5Dec= Take it? 
if %_2.5Dec%==1 (
set /A flsh=1 >inventory.bat
color 0a
@echo Congratulations! You just received your first item! 
@echo Altough it seems basic, use it as wisely as possible…
color 0
) else (
@echo You don’t exactly need a flashlight right now, so why to take it and make your pockets heavier? 
) 
@echo Once you’ve done everything you wanted, you turn your back on the wardrobe. 
@echo You sit to your table, right in front of the giant pile of books and papers.
@echo Taking a look at the book on the top, you recognize a cover of your favourite book, 
@echo Looks like you’ll have to sit down and read…
) else (
Pause
) 

As it gets to the line with if %_2Dec%==1..it just crashes.. Can someone please tell me why?

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Does it give you any error messages? \$\endgroup\$ – Bálint Jun 4 '19 at 9:12
1
\$\begingroup\$

There are multiple problems here, firstly, the parentheses in one of the echo messages messes up the nesting. You need to surround it with double quotes:

@echo "The first thing you notice (apart from the incredible mess) is a little silver flashlight, currently turned on."

Secondly, for reasons that are beyond me, the variable _2.5Dec expands when the _2Dec if statement runs. Since it doesn't have a value by then, it fails and the program stops. You need to use setlocal enabledelayedexpansion somewhere before the outer if statement and then use !_2.5Dec! in the inner if statement.

You'll also run into quite a bit of trouble later if you use the wrong "apostrophe", ` isn't the same as '

My main advice in using batch is don't.

\$\endgroup\$
3
  • \$\begingroup\$ Using a . in a variable name is odd. \$\endgroup\$ – Vaillancourt Jun 4 '19 at 15:43
  • \$\begingroup\$ @AlexandreVaillancourt Batch is odd. It's absolutely fine with it \$\endgroup\$ – Bálint Jun 4 '19 at 16:42
  • \$\begingroup\$ Yeah, I guess so. I like your main advice. \$\endgroup\$ – Vaillancourt Jun 4 '19 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.