Supplying a second noun for an NPC

Hello, I’m trying to supply missing second nouns, which is working for the player, but if I want an NPC to carry out the same action, the rule doesn’t seem to apply to them:

The battlefield is a room. "This is the battlefield"

The player is in the battlefield.

A weapon is a kind of thing. An axe and a sword are weapons. There is an axe and a sword in the battlefield.
An enemy is a kind of thing. A troll is an enemy in the battlefield.
The claws are a kind of weapon. The claws are a part of every person.
A sidekick is a kind of person. Bob is a sidekick in the battlefield.

Persuasion rule for asking Bob to try slashing:
	persuasion succeeds.
	
Persuasion rule for asking Bob to try taking:
	persuasion succeeds.

Slashing it with is an action applying to two things.
Understand "Slash [something]" as slashing it with.
Understand "Slash [something] with [a weapon]" as slashing it with.

Rule for supplying a missing second noun while slashing:
	If the player is carrying a weapon (called the weapon):
		Now the second noun is the weapon;
	Otherwise:
		Now the second noun is your claws.

Report an actor slashing:
	if the actor is the player:
		say "[The actor] hit [the noun] with [the second noun]!";
	otherwise:
		say "[The actor] hits [the noun] with [the second noun]!"

With this code, the following happens:

slash troll --> The player slashes the troll with his claws.
take axe / slash troll --> The player slashes the troll with the axe.
take sword / take axe / slash troll --> The player slashes the troll with the axe (the first item in the inventory, which is fine)

But,

Bob, take axe / Bob, slash troll --> Doesn’t work. The NPC doesn’t understand.
Bob, take axe / Bob, slash troll with axe --> Does work as intended.

I tried:

Rule for supplying a missing second noun while someone slashing:

or

Rule for supplying a missing second noun while an actor slashing:

but neither of those work.

Any help would be really appreciated.

P.S. I tried the command:

Bob, slash troll with your claws --> Doesn’t work. but,
Bob, slash troll with Bob’s claws --> Does, but sounds awkward. How could I give that command to Bob?

I think the culprit is this line, which I think is confusing the parser:

Understand "Slash [something]" as slashing it with.

If you delete it, the player will get a prompt for the missing second noun if they type BOB, SLASH TROLL (if you’d rather Bob makes his own decision in that situation, you can then put in something like “Does the player mean asking Bob to try slashing the troll with the axe: it is very likely.”)

As for your second issue, if you add these lines:

Understand "your claws" as the claws.  

Does the player mean asking Bob to try slashing the troll with Bob's claws: it is likely.

That should work (as well as in the BOB, SLASH TROLL WITH CLAWS case). Using “it is likely” for the claws but “it is very likely” for the axe means he prioritizes the weapon, which I think makes sense.

(NB that in your current code, nobody needs to be carrying a weapon to use it. If you want to add prioritization based on what the NPC currently has on them, you can tweak the Does the Player Mean commands by adding a “while Bob is carrying the axe/sword” so he prioritizes his claws while unarmed).

Hope this helps!

The syntax

Understand "Slash [something]" as slashing it with

is the correct syntax for invoking a ‘rule for supplying a missing second noun’ (see WI 18.32) and using a condition ‘while an actor slashing’ or ‘while an actor slashing something with’ is the correct syntax to include NPCs in that rule (see WI 18.32 Example 371- Latin Lessons).

See working code below using the ‘rule for supplying a missing second noun’.

I have tweaked the reporting code so that it reports ‘Bob hits the troll with his claws’ instead of the rather jarring ‘Bob hits the troll with Bob’s claws’.

The battlefield is a room. "This is the battlefield"

The player is in the battlefield.

A weapon is a kind of thing. An axe and a sword are weapons. There is an axe and a sword in the battlefield.
An enemy is a kind of thing. A troll is an enemy in the battlefield.
The claws are a kind of weapon. The claws are a part of every person.
A sidekick is a kind of person. Bob is a sidekick in the battlefield.

Persuasion rule for asking Bob to try slashing:
	persuasion succeeds.
	
Persuasion rule for asking Bob to try taking:
	persuasion succeeds.

Slashing it with is an action applying to two things.
Understand "Slash [something]" as slashing it with.
Understand "Slash [something] with [a weapon]" as slashing it with.

Rule for supplying a missing second noun while an actor slashing something with:
	If the person asked carries a weapon (called the weapon):
		Now the second noun is the weapon;
	Otherwise:
		If claws (called the weapon) are part of the person asked:
			Now the second noun is the weapon.

To hit is a verb.
Report an actor slashing:
	say "[The actor] [hit] [the noun] with [regarding the actor][their] [if second noun is claws]claws[else][second noun][end if]!"
		
Test me with "slash troll / take axe / slash troll / bob, slash troll / bob, take sword / bob, slash troll".
> battlefield
This is the battlefield

You can see an axe, a sword, a troll and Bob here.

>test me
(Testing.)

>[1] slash troll
You hit the troll with your claws!

>[2] take axe
Taken.

>[3] slash troll
You hit the troll with your axe!

>[4] bob, slash troll
Bob hits the troll with his claws!

>[5] bob, take sword
Bob picks up the sword.

>[6] bob, slash troll
Bob hits the troll with his sword!

Thank you, this solved the issue. The documentation for supplying second nouns did imply something similar, but it wasn’t quite as clear.

Just as a follow up, how would you generalize the following line:

Does the player mean asking Bob to try slashing the troll with Bob's claws: it is likely.

The following doesn’t compile, but I think you’ll understand the intent:

Does the player mean asking an actor to try slashing the troll with the actor's claws: it is likely.

Ah, that is tricky! This should work:

Does the player mean asking someone (called the foo) to try slashing an enemy with the claws (called the bar) when the bar is part of the foo: it is likely.

Wow, that actually did the trick! Thank you very much. It’s really difficult to infer what is acceptable syntax and what isn’t with this natural language style. I tried looking at Inform 6, since I’m somewhat familiar with C and C++, but it would take me months before getting anywhere with it.

Yeah, I definitely find there’s a fair bit of trial and error to figure out how exactly you need to phrase things! I have learned through hard experience that whenever you’re working with generic objects like these claws, which are distinguishable only by who they’re a part of, that “(called the WHATEVER)” syntax is really necessary since otherwise Inform will often have a hard time figuring out exactly which of the options you’re referring to.