Programming error found

I’m not sure how to report this. I got the following error message (transcript):

What do you do? **wield armor**

[** Programming error: tried to find the "parent" of nothing **]

You don't have that to wield.

for the following code

Rule for printing a parser error when the latest parser error is the can't see any such thing error:
	if the player's command includes "wield":
		if noun is not carried by the player:
			say "You don't have that to wield.";
		otherwise if noun is not a weapon:
			say "You can only wield [italic type]weapons[roman type] in your inventory.";

My game worked correctly, except for the error message interspersed.

1 Like

I think what’s going on is that this error only displays when the parser’s failed to construct a valid action, so “the noun” isn’t anything – so when you ask Inform to check what’s carrying it, it’s trying to walk up the ownership tree to find the “parent” of nothing, just like it says.

This is probably the kind of thing you want to implement as a check rule for wielding, rather than hacking the parser error rules; that way you’ll get the helpful default behavior where if the player tries to wield something that’s not actually in the scene, they’ll get the appropriate default messages, without you having to rebuild the parser manually.

4 Likes

I usually try to do that, but my actions are pre-empted by the parser not finding something called “armor” (although my player is in fact wearing armor).

Wielding is an action applying to one thing. Understand "wield [weapon]" as wielding.
Unwielding is an action applying to one thing. Understand "unwield [weapon]" as unwielding.

Rule for printing a parser error when the latest parser error is the can't see any such thing error:
	if the player's command includes "wield":
		if noun is not a weapon:
			say "You can only wield weapons in your inventory.";

I’m thinking I should say “wield [something]” instead of “wield [weapon]”; that way the parser will look for non-weapons and find something.

1 Like

Yeah, that’s exactly the thing to do.

1 Like

Mike,
Yes that worked. I removed the parser re-ruling and changed my actions a bit:

Wielding is an action applying to one thing. Understand "wield [something]" as wielding.

Check wielding:
	if noun is not a weapon:
		say "You can't wield that.";
	otherwise if noun is not carried by the player:
		say "You don't have that to wield.";
	if noun is wielded:
		say "It is already out and ready to strike."	;
	stop the action;		

Carry out wielding:
	if player carries a wielded weapon (called myWpn):
		try silently unwielding myWpn;
		say "Unwielding [myWpn] and wielding [noun]";
	now noun is wielded;

Report wielding:
	say "You wield the [noun]";
	after printing the name of a wielded thing: say " (wielded)";

I tested it against a weapon, armor worn, and something not an object, like “afsa”.

Question: Why doesn’t “wield [armor]” work instead of “wield [something]”, which requires a subsequent check for armor?

Having “wield [weapon]” and “wield [armor]” as two different understand statements pointing to the wield action is a viable approach; however, it’s generally more player friendly, as well as makes for cleaner code, to do the “wield [something]” approach with an appropriate check rule, since for example that means that the player will always see that that’s a valid action regardless of what they try to wield.

4 Likes

Although such understand phrases have their uses:

Understand “shoot [something]” as shooting. 
Understand “shoot [basketball]” as playing basketball. 

The key is to always have a fallback [something], even if it only functions to block an action.

3 Likes

It does work so long as you have defined armour as a kind of thing.

You can also do something like this.

An armour is a kind of thing.

Definition: a thing is armourable rather than unarmourable if it is an armour.

Thne you can say this.

"Wield [something armourable]" and "Unwield [something unarmourable]"

It’s actually best to have both. For example, if you have these two understand lines:

Understand "Wield [weapon]" as wielding. Understand "Wield [something]" as wielding.

The first one is more specific, so the wielding action will prefer wielding a weapon to a non weapon. Basically, a free “does the player mean” rule built in to the grammar lines!

Hope this helps.

2 Likes

I like the idea of a check action with “wield [something]” so that I don’t have to go into parser reprogramming. Thanks guys for all the help.