Looking at an undeads belongings

A skeleton wears a crown. The player can look at the crown by typing look at crown. But if he instead types look at skeletons crown, the game says that You can’t see any such thing.

I’m slightly puzzled at this …

[code]Deep Woods is a room. “The vegetation is dense. Only very little sunlight penetrates it.”

Skeleton is a person in Deep Woods. “An ordinary skeleton…”.

Crown is a thing. “An iron crown.”
The description of the crown is “The crown is made of iron. It looks heavy. Its surface is heavily ornamented.”

Crown is worn by skeleton.[/code]

Possessives aren’t built into Inform. You could define “skeleton’s” as a synonym for the crown (Understand “skeleton’s” as the crown.), or if you expect this to happen a lot in your game, use the extension Possession and Ownership by Shadow Wolf.

Thanks - I didn’t knew if this was normal behavior or if I had messed up somehow. That extension works quite well!

I tried creating a stealing action and ran into another wierd problem: [person wearing the noun] don’t work.
I suspect that I should use some sort of if the noun is worn by someone (called real owner): first, but I can’t get that to play along either.

Include Possession and Ownership by Shadow Wolf.

Understand "steal [something]" as stealing.
stealing is an action applying to one thing.

Check stealing:
	if the noun is not worn by someone:
		Say "You can't steal it - there don't seem to be any owner to steal it from." instead;
	
Carry out stealing:
	Now the player carries the noun.

Report stealing:
	Say "You steal the [noun] from [person wearing the noun]";


Deep Woods is a room. "The vegetation is dense. Only very little sunlight penetrates it."
Skeleton is a person in Deep Woods. "You see an ordinary skeleton.".
Crown is a thing. "An iron crown."
The description of the crown is "The crown is made of iron. It looks heavy. Its surface is heavily ornamented."
Crown is worn by skeleton.

The usual trick here would be to write something like “a random person who wears the noun.” You know and I know that there will always be one and only one person wearing the crown, but Inform doesn’t know it, and so often we need to use “a random…” to pick out the one thing that’s guaranteed to exist.

But! Something that complicates things here is that, by the time the Report rule runs, there isn’t anyone wearing the crown–you’ve already stolen it. There’s a way to check for whether someone was wearing the crown when the current action started by “if a person was wearing the crown” (see section 9.13 of the manual, Past and Present Tenses)–but that won’t let us do any nice stuff like “a random person who was wearing the crown” because descriptions like that have to be in the present tense. (“A random person who is wearing the crown” is fine, “a random person who was wearing the crown” isn’t.)

That seems like it messes up all the easy workarounds–so what I would do is use an action variable, as in section 12.10 of the documentation. Action variables are great when an action needs to keep track of something that isn’t the noun, the second noun, or the actor; for instance, the exiting action in the Standard rules has an action variable for the container exited from so it can keep track of what container you got out of even after you’ve got out of it. In this case we want to keep track of the person stolen from:

The stealing action has an object called the person stolen from (matched as "from").

That “matched as” lets us write things like “Check stealing from yourself” instead of “Check stealing when the person stolen from is yourself.”

Now, in order to get this to work, we need to find a way to tell Inform who the person stolen from is, which we do with a setting action variables rule:

Setting action variables for stealing: if the noun is worn by a person (called the real owner): now the person stolen from is the real owner.

This will leave the person stolen from as the default object “nothing” if no one is wearing the noun. (By the way, that’s why it needs to be an object rather than a person or thing, because “nothing” is an object but not a person or thing.)

And now we can write a Report rule that refers to the person stolen from even though that person isn’t wearing the noun anymore:

Report stealing: Say "You steal the [noun] from [the person stolen from].";

We can also use the action variable to tighten up our check rule:

Check stealing from nothing: Say "You can't steal [the noun] - there doesn't seem to be any owner to steal it from." instead;

and take care of special cases:

Check stealing from yourself: say "You deftly steal [the noun] from yourself. You don't notice a thing." instead.

My total code:

[code]Understand “steal [something]” as stealing.
stealing is an action applying to one thing.
The stealing action has an object called the person stolen from (matched as “from”).
Setting action variables for stealing:
if the noun is worn by a person (called the real owner):
now the person stolen from is the real owner.

Check stealing from nothing:
Say “You can’t steal [the noun] - there doesn’t seem to be any owner to steal it from.” instead;

Check stealing from yourself:
say “You deftly steal [the noun] from yourself. You don’t notice a thing.” instead.

Carry out stealing:
Now the player carries the noun.

Report stealing:
Say “You steal [the noun] from [the person stolen from].”;

Deep Woods is a room. “The vegetation is dense. Only very little sunlight penetrates it.”
The skeleton is a person in Deep Woods. “You see an ordinary skeleton.”.
The crown is a thing. “An iron crown.”
The description of the crown is “The crown is made of iron. It looks heavy. Its surface is heavily ornamented.”
The crown is worn by the skeleton.[/code]

Another note is that you should write “the crown” and “the skeleton” when you first define them if you want Inform to know that they’re common nouns that it can refer to as “the crown” and “the skeleton” rather than “Crown” and “Skeleton.” Then you can write “[the noun]” rather than “the [noun]” and Inform will automatically handle the definite articles for proper nouns and things with funny definite articles.

You will probably also want to consider the case where someone is holding the noun but not wearing it–if the player tries to steal something that’s being held but not worn they’ll get a confusing message. One way to handle this would be to consider the “enclosing” relation, which includes things that are held, worn, part of something else, contained by something else, and multiple layers (if the skeleton wears a hat that has a pocket that’s part of it and the pocket contains a gerbil, the skeleton will enclose the gerbil). Then you could write rules to take care of stealing worn things, stealing held things, making sure the player can’t steal parts of things, etc.

Thanks Matt, that was impressively in-depth! I think I got it now, but bookmarked for re-reading later. Lots of info to digest! :slight_smile: