Understand "here" as the holder of the player (does not compile)

(6M62)

Like the subject line says, Understand "here" as the holder of the player. doesn’t compile. But Understand "here" as the room enclosing the player. does. It’s just that I want “here” to refer to the direct holder of the player, not the room. Is there any way to crowbar this into a grammar line? I’d much rather do it via grammar than have to divert from some dummy “here” backdrop to make this work.

-Wade

current-here is an object that varies.

An room has a text called the hereafter.
A thing has a text called the hereafter.
Understand the hereafter property as describing an room.
understand the hereafter property as describing a thing.

when play begins:
now current-here is the holder of the player;
now the hereafter of current-here is "here".

After reading a command:
unless the current-here is the holder of the player begin;
now the hereafter of the current-here is "";
now the current-here is the holder of the player;
now the hereafter of the current-here is "here";
end unless.

maybe there’s something much cleverer, but this works.

I could be wrong, but I think this may be because Inform 7 already understands “here” as in:

Laboratory is a room. A workbench is here.

1 Like

nah, it’d be fine with doing this for every room in the game:

understand "here" as the lab when the holder of the player is the lab.
understand "here" as the parlor when the holder of the player is the parlor.

when you understand "foo" as the blah, the blah must be a particular fixed object. You can’t use a phrase or a variable: nothing dynamic.

Edited: well, ok, that syntax is used with a bunch of things that aren’t objects at all, like action names, or defining plurals, or new grammar tokens, so the “particular fixed object” part is wrong, but the “can’t use a phrase or variable that evaluates to an object” part is right.

1 Like

This seems to work:

Understand "here" as a thing when the item described is the holder of the player.
Understand "here" as a room when the item described is the holder of the player.

(The two lines are necessary because “object”, which would comprise both thing and room, doesn’t work. If you never need the room at all, you can leave it out, of course.)

See 17.17. Context: understanding when

3 Likes

Thanks all for the suggestions. I’ll go StJohn’s way because it has the least moving parts.

That said, it occurs to me I don’t really understand the logic of these ‘item described’ phrases work. They seem to involve a kind of lookahead or Catch 22. You type ‘x here’. How does it know what the item described is? Even if it looks at what the holder of the player is and then goes backwards to match it, well, ‘here’ isn’t grammar for that object that it knows.

Is it using a kind of ‘only one thing will fit’ logic. The player can only have one holder. So if you type ‘here’, we (who programmed it) know it can only come up with one result - the holder of the player, then matches ‘here’ to it. Am I getting in the zone?

-Wade

Under the hood, ‘Understand “blah” as a-kind when some-condition-or-other’ adds a routine to the I6 parse_name property of every instantiation of that kind (or class, in I6 terms) that causes the parser to recognise “blah” as a name for that object when the condition is true.

‘the item described’ is an I7 alias for the I6 variable ‘self’, which refers back to the specific instance of the object providing the property in question.

So, ‘Understand “here” as a thing when the item described is the holder of the player’ can be paraphrased as ‘attach a routine to every thing in the game, that recognises “here” as a name for that thing whenever that thing is the holder of the player’.

EDIT: this explains Zed’s observation that this style of Understand phrase must be attached to something solid- either a specific object or a kind- the compiler needs to know at compile-time exactly which object or objects’ parse_name properties to attach the routine to.

EDIT2: ‘Understand “here” as the holder of the player’ doesn’t work for 3 reasons. Firstly, Inform is looking for a description of a specific object or of a kind, which means the phrase has to be expressed in a slightly different way such as

Understand "here" as an object holding the player.

But Inform is also looking for something a bit more specific than an object- it wants a more specific kind that instances can inherit the parse_name property from. So:

Understand "here" as a thing holding the player
Understand "here" as a room holding the player

Which should work, but annoyingly falls foul of the bug (discussed elsewhere) whereby references to something vague rather than something specific holding something are interpreted by the compiler as meaning specifically carrying (and therefore applicable only to people), rather than the more usual 'carrying, or wearing, or containing, or supporting, or incorporating.* So we have to break it down further:

Understand "here" as a container containing the player
Understand "here" as a supporter supporting the player
Understand "here" as a room containing the player
(although 'thing' would also work in place of 'container' or 'supporter')

or

Understand "here" as a container which contains the player
Understand "here" as a supporter which supports the player
Understand "here" as a room which contains the player

*NB St John’s solution doesn’t fall foul of this bug for 2 reasons: firstly, because ‘the holder of <whatever>’ (which refers to a single (albeit variable) object) is not susceptible to it, whereas ‘the <vague whatever> holding <something>’ or ‘the <vague whatever> which holds <something>’ are; secondly, because ‘the item described’ also refers to a single (albeit variable) object - so ‘Understand “here” as a thing when the item described holds the player’ also works.

EDIT 3: You can also add adjectives to the kind, such as

Understand "here" as a lit room which contains the player.

Recall that Inform has to have a fixed object or kind to attach a parse_name routine to. An object’s location (e.g. co-located with the player or not) or properties (lit or unlit) may change during play, but not it’s fundamental being; similarly, a kind doesn’t change during play, nor the kind an object belongs to. So this ‘Understand…’ phrase will attach a parse_name routine to every room (not just those that happen to contain the player and be lit at the start of the game) but add conditions in the routine so that its logic only recognises “here” as a name for any specific room while that room is lit and contains the player.

4 Likes

Yep, the key is that “the item described” translates to self—that is, the owner of the current routine. It was originally going to be called “this object” but, in Graham’s words, “somehow this raised expectations too high about how often it would be meaningful: it looked like a pronoun running meanings from sentence to sentence”.

So instead it’s called “the item described” because it’s mainly used in the “printed name” and “description” properties, both of which are about describing a thing in some way. But it’s a bit of a misleading name when you’re writing Understand lines; “the thing under consideration” might be clearer.

2 Likes