ON PREVIEWING: Sequitur is in before me with many of the points I’d made. However, if you’re going to redirect wearing to the custom action you need to use a “before wearing” rule rather than an “instead of wearing” rule, I think, because the carrying requirements get checked between the “Before” and “Instead” rules; so an “instead of wearing the hood” rule will try to implicitly take the hood and get blocked.
I am going to start this post with a SPOILER: You should not try to allow the player to wear the hood. Do what Felix said and model wearing the hood with an either/or property of the cloak, or the player, or (what I think is best) the hood. The code that lets you wear the hood, and the reason why you shouldn’t do it, is in the spoiler tag.
[spoiler]
Unfortunately it’s a bit deeper than this. The wearing action is defined as “applying to one carried thing,” which I believe automatically forces the player to try taking something before wearing, and stops the action if the take fails. I think that some of the things around this will change in the next build of Inform, but in the meantime it is what it is.
Getting the carrying requirements not to apply to the action can be pretty annoying. capmikee has an extension that lets you do this. The thread that originally inspired the extension might allow us to come up with a special-case solution:
[code]An action-processing rule (this is the don’t need to take the hood rule):
if the current action is trying wearing the hood, continue the action;
abide by the carrying requirements rule.
The don’t need to take the hood rule is listed instead of the carrying requirements rule in the action-processing rulebook.[/code]
At this point we also need to fix the “can’t wear what’s not held” rule as Draconis suggested. (Most of the time the “can’t wear what’s not held” rule won’t fire, I think, because if you’re not holding the noun and can’t pick it up then the action will get stopped by the implicit take. But it serves as a backstop when a wearing action somehow manages to reach the check stage without the actor holding the noun – which is what happens when we tweak the carrying requirements rule.)
[code]Check an actor wearing (this is the new can’t wear what’s not held rule):
if the actor does not enclose the noun,
stop the action with library message wearing action number 2 for the noun.
The new can’t wear what’s not held rule is listed instead of the can’t wear what’s not held rule in the check wearing rulebook.[/code]
And now if you test our code, “wear hood” works! Hooray! But then if you try “wear hood/drop hood” we see the problem: When you wear the hood, it stops being part of the cloak. I believe the object hierarchy means everything has to have only one parent, if that’s the term: The hood can be part of the cloak, or worn by the player, but not both. So none of this will work.[/spoiler]
So what I’d do is make the hood part of the cloak, give it a property to determine whether it’s on or off, and redirect the actions of wearing the hood or taking the hood off so they go to changing that property rather than making the hood worn or not per se. Here’s an implementation, which surely has some issues:
[code]Lab is a room.
A thing can be identified or unidentified.
A hat is a kind of thing. It is wearable. Clothes are a kind of thing. They are wearable.
The tattered cloak is a clothes. It is unidentified. The description is “This hooded cloak might have been red once. It fits you perfectly.”
The tattered hood is part of the tattered cloak. The tattered hood is unidentified. The tattered hood can be on or off. The tattered hood is off.
The description of the tattered hood is “[IF UNIDENTIFIED]It’s part of the cloak[ELSE]Wearing this hood apparently conceals your cervine features[END IF].”
The player is wearing a tattered cloak.
Understand “cloak” as the tattered cloak.
Understand “hood” as the tattered hood.
The testcloak is a clothes. The player is carrying the testcloak.
The testhat is a hat. The player is carrying the testhat.
Hood-wearing is an action applying to one thing. [It won’t be triggered by a direct command, just redirected from wearing.] Before wearing the hood: try hood-wearing the hood instead.
Check hood-wearing the hood when the player does not wear the cloak: say “You have to be wearing the cloak before you can put the hood up.” instead.
Check hood-wearing the hood when the player wears a hat (called the chapeau): say “You can’t put the hood on over [the chapeau].” instead.
Carry out hood-wearing the hood: now the hood is on.
After hood-wearing the hood:
say “You pull the hood up over your head.[if unidentified]It conceals your cervine features![end if]”;
now the hood is identified.
Every turn when the player does not wear the cloak: now the hood is off.
Hood-removing is an action applying to one thing. Before taking off the hood: try hood-removing the hood instead.
Check hood-removing the hood when the player does not wear the cloak: say “You’re not wearing the cloak.” instead.
Check hood-removing the hood when the hood is off: say “The hood is already down.” instead.
Carry out hood-removing the hood: now the hood is off.
Report hood-removing the hood: say “You pull the hood down, revealing your antlers.”
[/code]
One thing is that you want to make sure that the rule for taking the hood off when the player takes off the cloak comes into effect soon enough; if you have an every turn rule that checks whether the hood is on, it might run before you’ve tested to see whether the player is wearing the cloak. Also the message for wearing the hood the first time prints on two separate lines. You’d also need to write something to make sure the player can type “put up hood” or “put hood up.” And I notice I didn’t write anything to prevent the player from putting the hat on over the hood.
BTW, you don’t need a line to understand “cloak” as the tattered cloak; unless you set an object as privately-named, the game will automatically understand every word in its name as it.