[noun] and [second noun]

I’m having trouble removing the cap from the tube of toothpaste:

[code]Removing is an action applying to one visible thing.

Understand “remove [noun] from [second noun]” as removing.[/code]

Cap is defined as part of the tube of toothpaste.

If you want to be able to remove it, you may need the cap and the tube to be two separate objects, instead of one being part of the other. If you make the tube a supporter, things can be put on it.

A supporter called a tube of toothpaste is in the bathroom. A cap is a thing on the tube of toothpaste.

“Removing it from” is already an action in Inform, so you may not need to add that.

Not sure if this is the best way, but hopefully it’s a step in the right direction.

Thanks. I had thought of that, but I wanted to see what others would suggest.
One thing your suggestion won’t do is prevent the player from squeezing the tube if the player hasn’t removed the cap.

Instead of squeezing the tube of toothpaste when the cap is on the tube of toothpaste, 	say "You'll have to take off the cap first."

Thanks for the suggestion, but that won’t work, either. The tube of toothpaste has been defined as a container – of toothpaste, natch.

First, there’s already an action for this, called “removing it from”.
Second, if your action is defined as applying to only one thing, it shouldn’t have two nouns in its grammar.
Third, you want “thing” here rather than “visible thing”, the latter removes the touchability requirement.
Finally, you don’t use [noun] and [second noun] in Understand lines. Those are the variables for the objects involved in the action. For Understand grammar, you need tokens like [something].

Thanks once again, Draconis!

To avoid making the tube of toothpaste a container, you could have a daub of toothpaste offstage, and bring it on when the player squeezes the tube. Something like this:

[code]A thing called a daub of toothpaste is nowhere.

Instead of squeezing the tube of toothpaste when the cap is not on the tube of toothpaste:
now the daub of toothpaste is on the toothbrush;
say “You squeeze some toothpaste onto the toothbrush.”[/code]

There’s more you’d have to do to make everything work right, but that’s the basic idea.

I thought Draconis’ suggestion would do it, but I’m still having trouble.

[code]The tube of toothpaste is a container on the sink.

The cap is part of the tube of toothpaste.[/code]

When I type:

“remove cap from tube”

the parser replies:

“You can’t see any such thing.”

That’s a nasty one (which we happened to be just discussing over here). The built-in “removing it from” action is designed for taking things from containers or supporters, and the grammar (“Understand”) lines for it use an obscure formulation that means that, if you try “remove sausage from box” and the sausage isn’t in the box, Inform doesn’t even recognize what “sausage” means! Which means you get the “You can’t see any such thing” message.

In this case, that means that since the cap isn’t contained in the tube of toothpaste, Inform doesn’t recognize the command.

So in this case you’d have to define a new Understand line for the removing it from action:

Understand "remove [something] from [something]" as removing it from.

And then you can write a rule for removing the cap from the tube:

Instead of removing the cap from the tube of toothpaste: if the cap is part of the tube of toothpaste: say "You take the cap from the tube of toothpaste."; now the player carries the cap; otherwise: say "The cap isn't on the tube of toothpaste."

This toy example and test script show how this works (and how some other examples of removing work):

[code]Bathroom is a room. The sink is in the bathroom. The tube of toothpaste is on the sink. The toothbrush is on the sink. The cap is part of the tube of toothpaste. The sink is fixed in place. The faucet is part of the sink.

Understand “remove [something] from [something]” as removing it from.

Instead of removing the cap from the tube of toothpaste:
if the cap is part of the tube of toothpaste:
say “You take the cap from the tube of toothpaste.”;
now the player carries the cap;
otherwise:
say “The cap isn’t on the tube of toothpaste.”

test me with “remove cap from tube of toothpaste/i/remove cap from tube of toothpaste/remove faucet from sink/remove tube from sink/remove tube from toothbrush”.[/code]

Wow! Worked perfectly. Thanks, matt w.