[I7] Tying two things with 1 object

A few searches didn’t turn up anything on this, though I figure it has been discussed before. I am looking at this example http://inform7.com/learn/man/ex316.html#e316 and wondering how best to modify this to my needs.

Here is a current test room code I’m working with that’s a modified version of this example:

"Hose Test" by Jizaboz

The Garden is a room. The hose is a thing in the Garden. The description of the hose is "An ordinary rubber hose[if the hose is part of something (called the parent)]. It is attached to [the parent][end if]."

A faucet is a thing in Garden. The description is "An ordinary faucet."  The handle is a thing in Garden. The description is "An ordinary spray handle."

After examining something when the hose is part of the noun:
	say "The hose is attached to [the noun]!"

[Here is the essential point: whenever we ATTACH HOSE TO something, it becomes part of that object.]

Instead of tying the hose to something:
	now the hose is part of the second noun;
	say "You attach [the hose] to [the second noun]."

[And of course the hose CAN be attached to more than one thing at a time. (But not itself)]

Instead of tying the hose to something when the hose is part of something:
	if the hose is part of the second noun:
		say "[The hose] is already attached to [the second noun]." instead;
	otherwise:
		now the hose is part of the second noun;
	say "You attach [the hose] to [the second noun]."

Instead of tying the hose to the hose:
	say "You can not attach the hose to itself"

Instead of taking the hose when the hose is part of something:
	say "Try detaching the hose first."

[Much of the rest is just tidying to make sure that the player's commands are redirected into the right syntax.]

Instead of tying something to the hose:
	try tying the hose to the noun.

Instead of putting the hose on something:
	try tying the hose to the second noun.

Instead of inserting the hose into something:
	try tying the hose to the second noun.

Understand the command "connect" as "tie".

Here is the result of a test play:

[code]Hose Test
An Interactive Fiction by Jizaboz
Release 1 / Serial number 111204 / Inform 7 build 6G60 (I6/v6.32 lib 6/12N) SD

Garden
You can see a hose, a faucet and a handle here.

x hose
An ordinary rubber hose.

x faucet
An ordinary faucet.

x handle
An ordinary spray handle.

attach hose to faucet
You attach the hose to the faucet.

x hose
An ordinary rubber hose. It is attached to the faucet.

x faucet
An ordinary faucet.

The hose is attached to the faucet!

attach hose to handle
You attach the hose to the handle.

x hose
An ordinary rubber hose. It is attached to the handle.

x handle
An ordinary spray handle.

The hose is attached to the handle!

[/code]

I would like the description to read “The hose is attached to the handle AND the faucet” and all variations thereof. This is something I’ve tinkered with at various times since I began learning Inform and still don’t grasp.

The hose can be part of only one object at a time (the handle or the faucet). That’s a basic rule of the I7 component relation. So the way you’ve chosen to model this isn’t going to work.

The easiest fix, for this case, is to reverse one of the relationships. The hose becomes part of the faucet, but the handle becomes part of the hose. It’s then easy to write descriptions that handle all four cases.

As a bonus, if the player picks up the hose with the handle attached, the handle will automatically come with it. (The faucet is presumably fixed in place.)

This model works for “big-to-small” attachment chains. It wouldn’t work if you wanted to attach the hose between two fixed objects.

Ah, I suspected that after seeing the behavior in my example. Thanks for confirming it. :slight_smile:

Cool, that makes sense. I was trying to do something like that with my last attempt before this.

You presume correctly. The faucet should be ‘fixed in place’ while the handle is not. The hose itself is not. Thanks for the advice, Zarf. I’ll try to add a post to this thread soon with the desired example code. I’m still kind of shady as to how this will all be described, but maybe I’ll have more understanding after edit this I code a bit as advised.

Have you looked at the Otranto example? That implements a rope that can be attached to two objects, though it goes a completely different way than the way you’ve been going. Not sure what the advantages of each approach are.

I had looked at that before and thank you for reminding me of it. Although at first glance months back I thought it did more than I wanted it to, “anchoring” the player when holding something attached to something fixed in place is important here and that probably would have been my next question.

I think I have enough to go on now for how I want to do this. Thanks again guys.

I have a couple ropelike things in my WIP, so I toyed with the idea of writing a rope extension. Unfortunately, I discovered that the general case is much harder to solve than two or three specific cases. But I can share with you some things from my WIP about describing connected objects…

I decided not to use incorporation, because not only does it prevent additional incorporation, it also prevents any other object-tree relation, such as carrying. So if you used Zarf’s method, you wouldn’t be able to hold the spray handle while it was attached to the hose.

[code]A watering attachment is a kind of thing. A watering attachment can be pumped or unpumped.

Garden is a room. A faucet is fixed in place watering attachment in the garden. A spray handle is a watering attachment in the garden. A hose is in the garden.

Patio is west of Garden.

Definition: The hose is dragging if the player encloses a pumped watering attachment.
Definition: A thing is externally visible if it is visible and it is not enclosed by the player and it is not the hose.
Definition: The hose is anchored if an externally visible watering attachment is pumped.

Section - Describing Connections

After choosing notable locale objects when the hose is anchored:
set the locale priority of the hose to 4;

After choosing notable locale objects when a externally visible watering attachment is pumped:
Repeat with the anchor running through externally visible pumped things:
set the locale priority of the anchor to 9;

For writing a paragraph about the hose when a externally visible watering attachment is pumped:
Let first end be a random pumped thing;
Let second end be a random pumped thing that is not first end;
say “The hose has one end hooked up to [the first end][if second end is not nothing] and [the second end] on the other end[end if].”;

For writing a paragraph about the dragging hose when every externally visible watering attachment is unpumped:
Let the source be a random pumped watering attachment enclosed by the player;
say “The hose runs from the [the source], with its free end dragging on the ground.”;

After printing the name of something enclosed by the player when writing a paragraph about the hose:
if the item described is carried:
say " (which you are carrying)“;
otherwise if the item described is worn:
say " (which you are wearing)”;
otherwise:
say " (which is in [the holder of the item described])";

After printing the name of a pumped watering attachment while taking inventory:
say " (with the hose attached to it)";

Last report examining the hose when a watering attachment is pumped:
Carry out the writing a paragraph about activity with the hose.

Last report examining a pumped watering attachment:
say “[The noun] is attached to the hose.”;

First report going when the hose is dragging:
say “The hose drags along behind you…”;

Section - Tying

The block tying rule is not listed in the check tying it to rulebook.

Check tying a watering attachment to the hose:
instead try tying the hose to the noun.

Check tying something that is not the hose to something:
say “Only the hose can be attached to things.” instead;

First check tying the hose to a pumped watering attachment:
say “That already has one end of the hose attached to it.” instead;

Check tying the hose to a watering attachment when at least two watering attachments are pumped:
say “There’s no free end.” instead;

Check tying the hose to something that is not a watering attachment:
say “[The second noun] can’t connect to the hose.” instead.

Check tying the hose to the hose:
say “The hose can’t connect to itself.” instead.

Carry out tying the hose to something:
Now the second noun is pumped;
Now the hose is in the location.

Report tying the hose to something:
say “You attach the hose to [the second noun].”;

Section - Managing hose connections

First check going when the player encloses the hose or the hose is dragging:
If an externally visible watering attachment is pumped:
say “You’ll have to disconnect the hose from [the list of externally visible watering attachments], or leave it behind.”;
stop the action;

Last carry out going (this is the drag the hose rule):
If the hose is dragging and the hose is not enclosed by the player, now the hose is in the holder of the player;

Last carry out entering:
Follow the drag the hose rule.

Last carry out exiting:
Follow the drag the hose rule.

Last carry out getting off:
Follow the drag the hose rule.

[we must also follow the drag the hose rule if we use the “move the player” phrase.]

Check taking the hose when a watering attachment is pumped:
Repeat with receptacle running through pumped watering attachments:
say “(disconnecting the hose from [the receptacle])[command clarification break]”;
Now the receptacle is unpumped.

test me with “get handle/attach handle to hose/l/x handle/x hose/w/l/x hose/e/attach hose to faucet/l/x faucet/x hose/i/w”[/code]

Excellent, capmikee! Not only is this what I’m looking for, I’m sure it will also serve as a great example to others trying to do this same thing in the future. Instead of wasting another hour or few getting this right (though the input from matt w and zarf helped me actually understand a bit more about this in general than I did), I’ve been spending that time playing with plugging my own things into your example. Thank you very much for taking the time to post it.

OK, one more little thing on this.

If I want to begin the game with the hoses already attached, what should I use?

now the hose is tied the faucet Doesn’t compile

the hose is part of the faucet Compiles, but it overrides the code in the example and permanently makes it a part of the faucet.

This is extremely ghetto, but it works-- assuming the player starts in the same room with the faucet and hose:

When play begins: silently try tying the hose to the faucet.

If the player is to start in some other room, this even-more-ghetto solution will work:

When play begins: silently try tying the hose to the faucet; move the player to patio, without printing a room description.

I’m not sure what example you’re referring to. If you mean my example, you need to use the “pumped” property, not a “tied to” relation or a “part of” relation:

When play begins: now the faucet is pumped

or if you want to use a declarative sentence:

The faucet is pumped.

Sorry about that cap. Yes, I was referring to your example.

I could have sworn I tried

When play begins: now the faucet is pumped.

first actually, but I guess I had a typo or something last night. Anyway, thanks for clearing that up.