Inform7:使用房间的属性

时间:2014-12-31 18:08:17

标签: runtime-error inform7

我对这种语言非常非常新,并且围绕“如何用东西做事”这个问题被证明是一种非常令人沮丧的努力。

我的目标是创建一个机械师,某些房间是危险的,并且玩家留在他们的时间越长就越危险。如果玩家长时间呆在危险的房间,就会触发死亡现场。

我的代码看起来像这样:

[The "danger rule"]
A room has a number called danger level. The danger level of a room is usually 0.

Definition: A room is dangerous if its danger level is 1 or more.
Definition: A room is deadly if its danger level is 9 or more.

Every turn (this is the increasing danger rule):
    If the player is in a dangerous room:
        Increase danger level by 1.

Every turn (this is the death by danger rule):
    If the room is deadly:
        do nothing.[Later...]

Every turn (this is the danger explanation rule):
    say danger level.

[further down]

The Feeding Chamber is south of the dungeon."You enter a large, dimly lit room with straw on the floor, surrounded by various cages embedded in the wall.[line break]Blood spatters are all over the floor, and it looks as if there's been a fight recently". After going to the feeding chamber for the first time:
    try looking;
    say "It smells like grues around here. I would be careful if I were you..";

The Feeding Chamber has danger level 5.

我似乎无法弄清楚如何正确使用“房间的危险等级”。我定义的解释规则在进入危险房间时会导致运行时错误:

`*** Run-time problem P31: Attempt to use a property of the 'nothing' non-object: property danger level`

..尝试将规则重新命名为the danger level of the roomthe danger level of this room会导致令人困惑的编译消息,例如:

`In the sentence 'say the danger level of the room'  , it looks as if you intend 'danger level of the room' to be a property, but 'a room' is not specific enough about who or what the owner is.`

以这种方式引用对象属性的“正确”方法是什么?

1 个答案:

答案 0 :(得分:2)

这里的神奇话语是" of the location"。如果我们暂时假装这是另一种编程语言,我写这篇文章的方式就好像我指的是一个班级" the room"而不是当前被引用的类的实例" the location"。

工作规则如下:

Every turn while the player is in a dangerous room:
        Increase danger level of the location by 1.

诀窍是给Inform足够的信息,以了解您所指的特定事物。原始问题中有问题的句子是完全有效的英语,人类可以解析,但计算机需要更多的帮助来确定我们说什么房间时我们说'#34;房间"。