Unsuccessful attempts

I’m having trouble figuring out how to report unsuccessful attempts correctly. The manual says something about using check and report rules, but I can’t find the relevant information about how to use them.

Apologies if this example is a little contrived - I’ve altered it to avoid spoilers in the hope that I’ll actually finish the game I’ve started:

[code]“Unsorted”

The Hall is a room.

The Sorting Hat is a neuter person in the Hall. The Sorting Hat is wearable.

Before taking the Sorting Hat, ignore the can’t take other people rule.

Understand “sort [something touchable]” as waking.

Persuasion rule for asking the hat to try waking the player: Persuasion succeeds.

Before the hat trying waking the player:
if the hat is not held:
say “The hat can’t sort you from where it is now.”;
otherwise:
try wearing the hat instead.

Unsuccessful attempt by the hat waking the player:
if the reason the action failed is the can’t wear what’s already worn rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
otherwise:
say “There is some kind of problem.”

test me with “hat, sort me/get hat/hat, sort me/hat, sort me”[/code]

So you see that in the case of failure, I get two messages. If the failure happens because of the Before rule, I get the default message from the hat’s action. If the failure happens because of the “can’t wear what’s already worn” rule, I get the default message from the player’s action. I don’t want either of these messages - I want just my custom message.

Looks like you need to stop the action when applicable and only test for the case where the hat isn’t worn…

[code]Before the hat trying waking the player:
if the hat is not held:
say “The hat can’t sort you from where it is now.”;
stop the action;
otherwise if the hat is not worn by the player:
try wearing the hat instead.

Unsuccessful attempt by the hat waking the player:
if the reason the action failed is the can’t wear what’s already worn rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
stop the action;
otherwise:
say “There is some kind of problem.”;
stop the action;[/code]
Although there might be more to it than that.

You’re right - that didn’t work. Thanks for the idea, though!

It looks like that’s because your Before rule asks the player to put on the hat whether or not it’s already worn. Try changing the before rule so it only tries putting the hat on if it’s not already worn (otherwise, it doesn’t need to do anything.)

Edit: Or am I missing the point?

Man, you’re too quick for me.
I edited my reply to include another idea I had, but you caught my post before I edited.
Try it with the testing for if the hat is worn, and let me know.

**Edit: Wow, gravel is quick, too!

I’m not sure I understand. I changed the Before rule to:

Before the hat trying waking the player if the hat is not worn:

And got this result with rules on:

So that doesn’t cause it to say “the hat is already on your head…” and it still gives two responses in the case where the hat is not held.

It looks to me as though the can’t wear what’s already worn rule automatically gives you the message “You’re already wearing that!” when it fires, so your “unsuccessful attempt” rule is bound to give you two messages in that case. In order to stop the first message from appearing, I think you’ll want to replace it:

[code]The can’t wear what’s already worn rule is not listed in any rulebook.

Check an actor wearing (this is the new can’t wear what’s already worn rule):
if the actor is wearing the noun:
if the noun is the sorting hat:
say “The hat is already on your head. It will give you an answer in a minute.” instead;
otherwise:
stop the action with library message wearing action number 3 for the noun. [/code]

Or something like that; didn’t test it. And then you can drop the corresponding part of your unsuccessful attempt rule.

You could do something similar to replace the can’t take other people rule instead of ignoring it sometimes (the 5Z71 documentation recommends only using “ignore” in procedural rules, which are now deprecated).

For the other part, does Joel’s suggestion of adding “stop the action” to the before rule work?

No, “stop the action” didn’t work.

I’m wary about unlisting rules. I tried looking in the manual some more - it seems like I’m supposed to give my own rules names in order to announce them as reasons for unsuccessful attempts. This now works correctly in the case of failure. Unfortunately, success is impossible!

[code]“Unsorted”

The Hall is a room.

The Sorting Hat is a neuter person in the Hall. The Sorting Hat is wearable.

Before taking the Sorting Hat, ignore the can’t take other people rule.

Understand “sort [something touchable]” as waking.

Persuasion rule for asking the hat to try waking the player: Persuasion succeeds.

Check the hat waking the player (this is the can’t wake what’s already awake rule): if the hat is worn, stop the action.

Check the hat waking the player (this is the can’t wake remotely rule): if the hat is not held, stop the action.

Carry out the hat waking the player:
try wearing the hat.

Unsuccessful attempt by the hat waking the player:
if the reason the action failed is the can’t wake what’s already awake rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
otherwise if the reason the action failed is the can’t wake remotely rule:
say “The hat can’t sort you from where it is now.”;
otherwise:
say “Something is wrong with my code.”

test me with “rules/hat, sort me/get hat/hat, sort me/wear hat/hat, sort me” [/code]

Is it possible to write a check rule that overrides the “block waking rule” for the hat, or do I have to unlist the “block waking rule” for all cases? Or can I do it with a Before rule like I did before?

I think you’re farther along than I am, but for the record, here’s what I got after some twiddling (I had to change “Check the waking the player” into “Check the hat trying waking the player”; that might be a 5Z thing, since I’m still running 5Z):

[code]“Unsorted”

The Hall is a room.

The Sorting Hat is a neuter person in the Hall. The Sorting Hat is wearable.

Before taking the Sorting Hat, ignore the can’t take other people rule.

Understand “sort [something touchable]” as waking.

Persuasion rule for asking the hat to try waking the player: Persuasion succeeds.

Check the hat trying waking the player (this is the must hold hat rule):
if the hat is not held and the hat is not worn:
stop the action;
otherwise:
try wearing the hat instead.

Check wearing the sorting hat (this is the can’t wear a worn hat rule):
if the hat is worn:
stop the action.

Unsuccessful attempt by the hat trying waking the player:
if the reason the action failed is the can’t wear a worn hat rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
otherwise if the reason the action failed is the must hold hat rule:
say “The hat can’t sort you from where it is now.”;
otherwise:
say “There is some kind of problem.”

test me with “hat, sort me/get hat/hat, sort me/hat, sort me”[/code]

Which yields:

Almost there, but the last fershlugginer step doesn’t work. It seems to me that “the reason the action failed” probably reports the name of any check rule that caused the action to fail – step 1 didn’t work until I changed the “must hold hat” rule from a before rule to a check rule. I see you’ve done that already with the “can’t wake remotely” rule.

Unfortunately, at step 4, the “must hold hat” rule is the check trying the hat waking rule that calls the “can’t wear a worn hat rule”, so it looks like the reason the action failed is still coming up as “must hold hat”. At least that’s my theory; I don’t know a lot about checks and unsuccessful attempts. (Also, I had to change the condition on the must hold hat rule because a worn hat isn’t held. UPDATE: Your solution of breaking it up into two check rules solves the problem, since now when the hat is worn, it’s a check waking rule that leads to the failure. And anyway it’s more elegant.)

Hm, I thought I had something else about the “block waking” rule, but I seem to have deleted it when I tried to update my post. Anyway, my suggestion was to redirect “waking” to a new action, “hatwaking,” but then I realized that a much easier thing to do would just be to understand “sort” as hatwaking instead of waking. Then you don’t have to worry about the standard block waking rule at all.

If you want to allow “hat, wake me” as well as “hat, sort me,” this seems to work:

Instead of asking the Sorting Hat to try waking yourself: try asking the sorting hat to try hatwaking yourself.

Not sure how well it generalizes (or why I couldn’t accomplish that using an “understand” phrase, though the answer may be my incompetence.)

So here’s what I’ve got, which I think does what you want:

[code]“Unsorted”

The Hall is a room.

The Sorting Hat is a neuter person in the Hall. The Sorting Hat is wearable.

Before taking the Sorting Hat, ignore the can’t take other people rule.

Understand “sort [something touchable]” as hatwaking.

Hatwaking is an action applying to one thing.
Persuasion rule for asking the hat to try hatwaking the player: Persuasion succeeds.

Instead of asking the Sorting Hat to try waking yourself:
try asking the sorting hat to try hatwaking yourself.

Check the hat trying hatwaking the player (this is the can’t wake what’s already awake rule): if the hat is worn, stop the action.

Check the hat trying hatwaking the player (this is the can’t wake remotely rule): if the hat is not held, stop the action.

Carry out the hat trying hatwaking the player:
try wearing the hat.

Unsuccessful attempt by the hat trying hatwaking the player:
if the reason the action failed is the can’t wake what’s already awake rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
otherwise if the reason the action failed is the can’t wake remotely rule:
say “The hat can’t sort you from where it is now.”;
otherwise:
say “Something is wrong with my code.”

test me with “rules/hat, sort me/get hat/hat, sort me/wear hat/hat, sort me/hat, wake me”[/code]

I’ve got it!

Reviewing the guidelines for action rules, I noticed that redirecting an action should be done in a Before rule. Makes sense. So I have check rules to explain why the hat can’t be worn, and a very specific Before rule to override all the blocking rules. Putting all the same conditions in the Before rule seems redundant, but it works:

[code]“Unsorted”

The Hall is a room.

The Sorting Hat is a neuter person in the Hall. The Sorting Hat is wearable.

Before taking the Sorting Hat, ignore the can’t take other people rule.

Understand “sort [something touchable]” as waking.

Persuasion rule for asking the hat to try waking the player: Persuasion succeeds.

Check the hat trying waking the player (this is the can’t wake what’s already awake rule): if the hat is worn, stop the action.

Check the hat trying waking the player (this is the can’t wake remotely rule): if the hat is not held, stop the action.

Before the hat trying waking the player when the hat is held and the hat is not worn:
try wearing the hat instead.

Unsuccessful attempt by the hat waking the player:
if the reason the action failed is the can’t wake what’s already awake rule:
say “The hat is already on your head. It will give you an answer in a minute.”;
otherwise if the reason the action failed is the can’t wake remotely rule:
say “The hat can’t sort you from where it is now.”;
otherwise:
say “Something is wrong with my code.”

test me with “hat, sort me/get hat/hat, sort me/wear hat/hat, sort me”[/code]

I added “trying” in the hopes that this will run in your 5Z version…

That’s a nice, elegant solution - not as redundant as mine. I was irrationally afraid of creating a new verb, but I think that’s actually a good course of action in this case.

Although it does run into the same problem as unlisting the block waking rule:

I’d need to write a more general “carry out hatwaking” rule, or a more specific “check hatwaking” rule to cover situations like that.

Yeah, default behavior for hatwaking is needed. On a quick check, a “carry out hatwaking” rule seems to work without messing with any of the other behavior.

My instinct is that it’s generally better to try to create new actions than repurpose old ones, just because when you’re repurposing old actions you may run into Standard Rules that you don’t want and are a pain to work around. (But this is me acting like I’m not a noob again.)

UPDATE: Your solution works too. And apparently worn things do count as held, so I don’t know what I was doing there.

You’re right, although the manual doesn’t quite articulate that fact. Page 3.20 says this:

“(When we come to asking questions about the current situation, we will need to remember that “to carry” and “to wear” are different. Thus “if Lancelot carries the plate armour” will not be true if he is wearing it rather than carrying it under his arm. As we will later see, we can instead vaguely say “if Lancelot has the plate armour” to mean either carrying or wearing.)”

This passage doesn’t address the question of whether “held” is the same thing as “carried,” however.

It’s not – even though, to a native English speaker, the two words mean the same thing. “Carried” means the object is positioned within the player object in the object tree, but not worn. “Held” means “either carried or worn” – another little Inform idiosyncrasy.

–JA

That’s not quite true. If I have a book in my backpack, I’m carrying it but not holding it. Of course that cuts the opposite way from the actual distinction. (For that matter, if I were holding anything right now, I wouldn’t be carrying it, because I’m sitting down and not moving.) But the manual definitely doesn’t explain the distinction very well – there’s a bit where it mentions “held” as meaning “in inventory,” but that’s very indirect.