【问题标题】:trouble with Batch (if statements)批处理问题(如果语句)
【发布时间】:2014-01-10 13:10:59
【问题描述】:

我正在批量制作游戏。我知道那批不是很强大,但这是我的第一场比赛。无论如何,我正在做一个 if 语句,如果您通过 1 号门,您将活着,但如果您通过 2 号门,您将死去。不幸的是,当我通过任何一扇门时,程序都会重新启动。在这里,我将向您展示我的代码:

`@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` 

注意:我正在使用 Notepad++ 编程。还没完结啊。

【问题讨论】:

  • 如何运行这个脚本?将其保存到 *.bat 文件并从命令行运行它?

标签: text adventure


【解决方案1】:

目前,两个条件都不为真,程序根本不跳转。它执行“youDie”位,因为程序自然会进入下一行。无论用户输入如何,这两个条件都评估为假的原因是 if 语句将字符串“answer1”而不是变量“answer1”与数字进行比较。正确的语法是:if %answer1%==1 goto youLive

【讨论】:

    【解决方案2】:

    你没有做%answer1%所以它不起作用。

    您正在比较单词 answer1 而不是变量。

    就像你写%name%一样,你需要对答案做同样的事情。

    调试时(寻找脚本中的问题),不要关闭回显。

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2014-11-14
      • 2014-03-05
      • 1970-01-01
      相关资源
      最近更新 更多