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

发布于 2024-10-24 13:01:48 字数 535 浏览 4 评论 0原文

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.

“在休息室里制作一杯汽水(称为流行音乐)。”显然这不是一个有效的命令,但我希望它能传达我想要做的事情。我不知道如何在运行时实例化对象。这可以合理地完成吗?任何帮助将不胜感激。我知道 Inform 的粉丝不多,但我想我应该尝试一下。

Very new to Inform7 and it's style. I have looked through the provided docs and some internet browsing has yielded nothing for me... this is a simplistic version of what i'm looking for. I want to write something like this:

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.

"create a soda pop (called pop) in the breakroom." is not a valid command obviously, but I hope it conveys what I want to do. I don't know how to instantiate objects at runtime. Can this be done reasonably? Any help would be appreciated. I am aware that there's not a big following here for Inform but I figure i'd give it a shot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当爱已成负担 2024-10-31 13:01:48

Inform 不能很好地处理动态对象,但无论如何它们通常都不是最好的方法。 10.3 节。手册中的小物体分配器和用品可能会有所帮助。

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

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.

>

Inform doesn't handle dynamic objects very well, but they're often not the best approach anyway. Section 10.3. Dispensers and Supplies of Small Objects in the manual may be helpful.

I think the best model for this is a physical one: create a limited supply of cans in the machine. For example:

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".

(make the machine opaque rather than transparent if you prefer!). In the above, I've also tweaked the description of a soda pop -- if you just say "Blah" rather than The description is "Blah" after an object definition, you set the initial description (printed as part of the room description) rather than the "examine" description, which I don't think is what you want here -- and I've made the button a "part" of the machine, rather than a separate object.

The result:

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.

>
吃素的狼 2024-10-31 13:01:48

我编写了一个扩展来执行此类操作: https ://github.com/i7/extensions/blob/master/Jesse%20McGrew/Dynamic%20Objects.i7x

要使用它,您必须创建一个原型对象(例如“原始汽水”) ),然后使用表达式从原始汽水克隆的新对象来实例化新对象。这比创建大型静态对象池更节省内存,但它不适用于 Z 机器(仅 Glulx),并且如果您的对象很复杂,则有一些警告。

另外,请认真考虑您是否真的需要动态对象创建。如果您只是想出一个合理的理由来拒绝该操作,例如“当您甚至还没有喝完最后一杯苏打水时,您就无法让自己花钱”,那么对于玩家来说,这可能会更容易,也不会那么混乱。周围有几千个汽水罐可能会减慢游戏速度,但不会带来太多好处。

I wrote an extension to do this sort of thing: https://github.com/i7/extensions/blob/master/Jesse%20McGrew/Dynamic%20Objects.i7x

To use it, you'd have to create a prototype object (say, "the original soda pop"), then use the expression a new object cloned from the original soda pop to instantiate the new object. This is more memory-efficient than creating a large static pool of objects, but it doesn't work on the Z-machine (only Glulx) and has some caveats if your objects are complicated.

Also, think seriously about whether you really need dynamic object creation. It may be easier and less confusing for players if you just come up with a sensible reason to reject the action, like "You can't bring yourself to spend the money when you haven't even finished the last soda you bought." Having a couple thousand soda cans lying around is likely to make the game slower without adding much benefit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文