首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在inform7中创建新对象时需要帮助

在inform7中创建新对象时需要帮助
EN

Stack Overflow用户
提问于 2011-03-22 11:10:23
回答 2查看 1.4K关注 0票数 9

非常新的Inform7和它的风格。我已经看过了提供的文档,但一些互联网浏览对我没有任何帮助。这是我正在寻找的东西的简单化版本。我想写这样的东西:

代码语言:javascript
复制
breakroom is a room. "A run of the mill breakroom."

soda pop is a kind of thing. "A refreshing soda pop."

soda machine is in the breakroom.  dispense button is on the soda machine.

instead of pushing dispense button:
    say "A soda can dispenses".
    create a soda pop (called pop) in the breakroom.

“在休息室中创建汽水汽水(称为汽水)。”显然不是一个有效的命令,但我希望它能传达我想要做的事情。我不知道如何在运行时实例化对象。这样做是否合理呢?任何帮助都将不胜感激。我知道这里没有大量的追随者,但我想我会试一试。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-03-25 05:52:52

Inform不能很好地处理动态对象,但无论如何它们通常都不是最好的方法。手册中的10.3. Dispensers and Supplies of Small Objects一节可能会有所帮助。

我认为最好的模型是物理模型:在机器中创建有限的罐头供应。例如:

代码语言:javascript
复制
Breakroom is a room. "A run of the mill breakroom."

A soda pop is a kind of thing.  The description is "A refreshing soda pop."

The soda machine is in the breakroom.  It is fixed in place and transparent.
The description is "Just an average soda machine, with a large dispense
button."

There are three soda pops in the soda machine.

The dispense button is a part of the soda machine.

Instead of pushing the dispense button:
        if a soda pop (called the can) is in the soda machine:
                move the can to the breakroom;
                say "A soda can dispenses.";
        otherwise:
                say "The machine is empty, so nothing happens.".

Test me with "look / x machine / push button / look / push button /
push button / push button / look".

(如果您愿意,可以将机器设置为opaque而不是transparent!)。在上面的内容中,我还调整了对汽水的描述--如果您只是在对象定义后说"Blah"而不是The description is "Blah",那么您设置的是初始描述(打印为房间描述的一部分)而不是“检查”描述,我认为这不是您在这里想要的描述--我还使按钮成为机器的一个“部分”,而不是一个单独的对象。

结果是:

代码语言:javascript
复制
Welcome
An Interactive Fiction
Release 1 / Serial number 110324 / Inform 7 build 6G60 (I6/v6.32 lib 6/12N) SD

Breakroom
A run of the mill breakroom.

You can see a soda machine (in which are three soda pops) here.

>test me
(Testing.)

>[1] look
Breakroom
A run of the mill breakroom.

You can see a soda machine (in which are three soda pops) here.

>[2] x machine
Just an average soda machine, with a large dispense button.

In the soda machine are three soda pops.

>[3] push button
A soda can dispenses.

>[4] look
Breakroom
A run of the mill breakroom.

You can see a soda pop and a soda machine (in which are two soda pops) here.

>[5] push button
A soda can dispenses.

>[6] push button
A soda can dispenses.

>[7] push button
The machine is empty, so nothing happens.

>[8] look
Breakroom
A run of the mill breakroom.

You can see three soda pops and a soda machine (empty) here.

>
票数 8
EN

Stack Overflow用户

发布于 2011-04-15 12:13:14

我写了一个扩展来做这类事情:https://github.com/i7/extensions/blob/master/Jesse%20McGrew/Dynamic%20Objects.i7x

要使用它,您必须创建一个原型对象(比如“原始soda pop"),然后使用表达式a new object cloned from the original soda pop实例化新对象。这比创建一个大型静态对象池更节省内存,但它不能在Z机(仅Glulx)上工作,并且如果您的对象很复杂,则需要注意一些问题。

此外,请认真考虑是否真的需要动态对象创建。如果你只是想出一个合理的理由来拒绝这个动作,比如“你甚至还没有喝完你买的最后一瓶汽水,你就不能花掉这笔钱,这对玩家来说可能会更容易,也不会让你感到困惑。”有几千个苏打罐放在周围可能会让游戏变得更慢,而不会增加太多好处。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5386306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档