【问题标题】:Batch script not working(using notepad++ for this)批处理脚本不起作用(为此使用记事本++)
【发布时间】:2014-09-04 05:01:19
【问题描述】:

基本上,我正在制作一个类似于“捡起钥匙”或“击中怪物”类型游戏的脚本...

这就是问题所在。我做的功能

:beginning2
cls
echo You're in a room with a broken glass, a chest, a mirror, a counter with a small object on it, and a door.
echo What do you want to do?
set /p beginning2=Action:

if "%beginning2%"=="look at counter" goto counter

它应该转到脚本的这一部分的“计数器”。

:counter
cls
echo There is a small object on this counter.
echo It appears to be a key.
set /p counter=Action:

if "%counter%"=="pick up key" goto beginning3

这是整个脚本。

@echo off
color 0a
:beginning1
cls
title Adventure
echo You're in a room with a broken glass, a chest, and a mirror.
echo The room has no light.
echo What do you want to do?
set /p input=Action:

if "%input%"=="open chest" goto chest
if "%input%"=="look at mirror" goto mirror

:beginning2
cls
echo You're in a room with a broken glass, a chest, a mirror, a counter with a small object on it, and a ab door.
echo What do you want to do?
set /p beginning2=Action:

if "%beginning2%"=="look at counter" goto counter

:beginning3
cls
echo You're in a room with a broken glass, a chest, a mirror, a counter with nothing on it, and a door.
echo You also hold a key.
echo What do you want to do?
set /p beginning3=Action:

if "%beginning3%"=="open chest" goto chest2
if "%beginning3%"=="look at counter" goto counter

:beginning4
cls
echo You're in a room with a broken glass, an opened chest, a mirror, a counter with nothing on it, and a door.
echo You also hold a key.
echo What do you want to do?
set /p beginning4=Action:

if "%beginning%"=="open door" goto door

:chest
cls
echo The chest is locked. What do you want to do now?
set /p chest=Action:

if "%chest%"=="back" goto beginning1
if "%chest%"=="look at mirror" goto mirror

:chest2
cls
echo You hold a key, and a chest appears infront of you.
echo What do you want to do now?
set /p chest2=Action:

if "%chest2%"=="open chest" goto chest3

:chest3
cls
echo The chest clicks open!
echo In it appears to be another key, but slightly bigger.
echo What do you want to do now?
set /p chest3=Action:

if "%chest3%"=="back" goto beginning4

:mirror
cls
echo You look in the mirror.
echo You see nothing because the room has no light.
echo What do you want to do now?
set /p mirror=Action:

if "%mirror%"=="turn on lights" goto lights
if "%mirror%"=="back" goto beginning1

:lights
cls
echo You turned on the lights!
echo You've revealed a counter with a small object on it, and now there is light in the mirror.
set /p lights=Action:

if "%lights%"=="look at mirror" goto mirror2

:mirror2
cls
echo You look at a mirror, you see yourself with a pen mark on your arm that says "0212"
set /p mirror2=Action:

if "%mirror2%"=="back" goto beginning2

:counter
cls
echo There is a small object on this counter.
echo It appears to be a key.
set /p counter=Action:

if "%counter%"=="pick up key" goto beginning3

:door
cls
echo You go to the door with a key, and open it. It clicks open simply.

请帮助我,因为这太令人沮丧了。这很奇怪,因为它只是说“goto counter”,但它对我不起作用。

【问题讨论】:

  • 题外话:你们怎么会用批处理文件制作游戏?为什么不使用普通的编程语言?即使使用 Perl 在 cmd 中输入和输出,开发游戏也会容易得多。
  • 如果您制作基于控制台的游戏,我会推荐 python。快速、简单且易于学习。

标签: windows batch-file notepad++


【解决方案1】:

使用 if 语句时,它们默认区分大小写。使用/i 来改变这个:

set /p beginning2=Action:

if /i "%beginning2%"=="look at counter" goto counter

【讨论】:

    【解决方案2】:

    我查看了您程序的控制流程,这是它的选项树:

    :beginning1 (broken glass, a chest, and a mirror)
    - "open chest": goto chest
    - "look at mirror": goto mirror
    - else:
    :beginning2 (broken glass, a chest, a mirror, a counter with..., and a ab door)
    - "look at counter": goto counter
    - else:
    :beginning3 (broken glass, a chest, a mirror, a counter with nothing..., and a door)
    - "open chest": goto chest2
    - "look at counter": goto counter
    - else:
    :beginning4 (broken glass, an opened chest, a mirror, a counter with nothing, and a door)
    - "open door": goto door
    - else:
    :chest (chest is locked)
    - "back": goto beginning1
    - "look at mirror": goto mirror
    - else:
    :chest2 (chest appears infront of you)
    - "open chest": goto chest3
    - else:
    :chest3 (chest clicks open)
    - "back": goto beginning4
    - else:
    :mirror (look in the mirror)
    - "turn on lights": goto lights
    - "back": goto beginning1
    - else:
    :lights (turned on lights)
    - "look at mirror": goto mirror2
    - else:
    :mirror2 (look at a mirror)
    - "back": goto beginning2
    - else:
    :counter (small object on counter)
    - "pick up key": goto beginning3
    - else:
    :door (open door)
    -> terminate program
    

    我运行您的程序,它的行为与编程完全一致。例如,在“:lights”标签处,如果输入“look at mirror”程序执行“goto mirror2”;否则,如果您输入的内容与“查看镜像”不同,程序会继续下一行,即“:mirror2”...

    我认为您必须在先前方案指定“- else:”的每一行插入带有适当标签的goto...

    您还应该在所有 if 命令中包含 /I 开关,如 Monacraft 所示,除非您确定用户将始终以小写字母输入命令...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多