trouble with Batch (if statements)

41 views Asked by At

I'm making a game in Batch. I know that batch isn't very powerful but it's my first game. Anyways I'm making an if statement and if you go through door 1 you will live but if you go through door two you die. Unfortunately when I go through either door the program restarts. Here, I will show you my code:

`@echo off
color 02
::stats 
set Badasspts=0

:Beginning
echo Hello what is your name?
set /p name=
echo Hello %name%!
echo You have two doors to go through. Which one? Possible answers: 1 or 2
set /p answer1=
if answer1==1 goto youLive
if answer1==2 goto youDie
:youDie
echo Behind this door is an alligator pit you accidentally fall in and die!
goto Beginning

:youLive
echo Well... well... well... you live this time but now ummm... A wild monster appears. What do you do? Possible answers: hug, attack
set /p hugAttck=
if hugAttack==hug goto hug
if hugAttack==attack goto attack1

:hug
echo You hug that cute furry monster soooo hard that he dies. Plus 1 BADASS points!!!!
pause` 

Notes: I'm programming in Notepad++. It is not finished yet sooo yeah.

2

There are 2 answers

0
Marcks Thomas On

Currently, neither condition evaluates to true and the program does not jump at all. It executes the 'youDie' bit because the program naturally proceeds to the next line. The reason both conditions evaluate to false, regardless of user input, is that the if statements compare the string 'answer1' instead of the variable 'answer1' to a number. The correct syntax would be: if %answer1%==1 goto youLive.

0
AturSams On

You did not do %answer1% so it does not work.

You are comparing the word answer1 and not the variable.

Just like you write %name%, you need to do the same with answer.

When you debug (looking for problems in the script), don't turn echo off.