Object 需要在inform7中创建新对象的帮助吗

Object 需要在inform7中创建新对象的帮助吗,object,creation,inform7,Object,Creation,Inform7,Inform7非常新,它的风格。我已经查看了提供的文档,一些网络浏览对我来说没有任何结果。。。这是一个简单的版本,我正在寻找的。我想写这样的东西: 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 ma

Inform7非常新,它的风格。我已经查看了提供的文档,一些网络浏览对我来说没有任何结果。。。这是一个简单的版本,我正在寻找的。我想写这样的东西:

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.

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

Inform不能很好地处理动态对象,但它们通常不是最好的方法。手册中的章节可能会有所帮助

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

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".
(如果愿意,将机器设置为
不透明
而不是
透明
)。在上面,我还调整了苏打汽水的描述——如果你只是说
“Blah”
而不是
,那么描述是“Blah”
在对象定义之后,你可以设置初始描述(作为房间描述的一部分打印)而不是“检查”描述,我不认为这是你想要的——我把按钮做成了机器的“一部分”,而不是一个单独的物体

结果是:

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.

>

我写了一个扩展来做这类事情:

要使用它,您必须创建一个原型对象(例如,“原始soda pop”),然后使用表达式
从原始soda pop克隆的新对象来实例化新对象。这比创建大型静态对象池的内存效率更高,但它在Z-machine(仅Glulx)上不起作用,并且在对象复杂时有一些警告


此外,请认真考虑是否确实需要创建动态对象。如果你能想出一个合理的理由拒绝这项行动,比如“你连买的最后一瓶苏打水都还没喝完,你就不能让自己花钱了”,那么对玩家来说,这可能会更容易,也不会让他们感到困惑有几千个苏打罐放在周围可能会使游戏速度变慢,但不会增加太多好处。

谢谢您的帮助。我今天早上才注意到你刚才提到的例子。这是一个很好的帮助。不过,接下来,如果我说机器中有2000个POP,它会占用大量内存,还是会在最小的空间中存储一堆相同的对象。(即,如果1个pop是100字节,那么2000个pop是100x2000字节吗?)这一个没关系。使用提供的链接,有一句话描述了每个对象实际上都消耗了内存。这是有道理的。下面是我计划做的一个具体例子。我有一棵灌木,每6小时结一次浆果。这些浆果可供玩家以后食用或储存。虽然我可以很容易地找到一个玩家一次可以携带的浆果数量的实际限制,但我似乎正在编写代码,在被吃掉或丢弃后,将这些浆果从虚空中复活,与在创建和食用时实例化和销毁浆果相比,该代码似乎不是很优雅。无论如何,感谢扩展链接,我会查看它。扩展不允许您破坏对象,只允许创建新的对象(因为I7缺少避免悬空指针所需的内省功能)。所以你仍然需要写一些回收代码。