Punctuation within Understand

Wondering if there’s a way to bypass the system to allow something like

Crying is an action applying to nothing. Understand "wail!" as crying.

without Inform getting mad at you about the “understand” text containing literal punctuation. (Presumably I’m getting this error because the parser reacts to ending punctuation like exclamation points differently, but I don’t see how that would have an affect on the player’s parser inputs.)

Thanks in advance for the assistance!

Could you maybe just have it as understand "wail" as crying. but in its rules check whether the player’s command includes the character “!”?

Not sure if this is what you mean, but adding

Check crying:
	if the player’s command includes “!”:
		continue the action.

comes up with the same error.

To be clear: Is your goal that the player must include the exclamation point in order to generate a crying action, or is it just that the parser recognize >WAIL! alongside >WAIL as a way of generating a crying action?

If the latter, you may find Emily Short’s Punctuation Removal extension (installed but not active by default) to be useful.

2 Likes

The parser splits out ending punctuation before trying to recognize verbs. This is why the compiler is reporting that error.

You need to do some trick similar to Punctuation Removal, which runs “after reading the player’s command”.

1 Like

Yay! This was indeed solved with the punctuation extension, at least for my game. However, I wonder for the future if there’s an elegant way within the extension (or perhaps without) to remove the exclamation points on SOME commands but not others? Or to only register the action if it includes an exclamation point?

Something here might help: §18.33. Reading a command.

Sorry for leading you astray earlier. The perils of a little knowledge and a mobile-friendly forum!

2 Likes

There are ways to do these, but the methods I have found aren’t exactly elegant.

For the first part, regarding removing exclamation points from some commands but not others…

To start, I’m not sure that I would recommend doing this. I think that most players rightfully prefer consistency in parser responses. Without pretty explicit prompting, it would be very hard to learn under which circumstances an exclamation point is allowed/required vs. when it is not. Still, as a technical matter, this can be accomplished without too much hassle by setting up a topic (or group of topics) with the verb words to which you want to attach the requirement.

"Exclamations Sometimes"

Include Punctuation Removal by Emily Short.

Place is a room.

Crying is an action applying to nothing.

Report crying:
    say "You cry for a bit."

Understand "wail" or "cry" or "lament" as "[wail word]". [creates a topic to use in matching]

Understand "[wail word]" as crying. [uses topic as basis for understanding verb; may break if the same verb words are used for other verbs as seen in https://intfiction.org/t/bug-topic-based-actions-not-parsed-if-they-share-a-verb-word-with-another-action/50281]

After reading a command:
    let temp storage be the substituted form of "[player's command]"; [see WWI 20.7 Making new text with text substitutions]
    remove exclamation points; [have to do this so that topic matching works correctly; handling of exclamation marks seems a bit inconsistent internally]
    unless the player's command matches "[wail word]": [see WWI 18.33 Reading a command]
	    change the text of the player's command to temp storage. [reverts to text including exclamation mark if a "wail word" not seen after their removal]

Test me with "jump / jump! / wail / wail!". [note that >JUMP! doesn't work but >WAIL! does]

For the second part, regarding allowing only commands with exclamation marks…

Advisability aside, as a technical matter, this can be accomplished with some I6-level manipulation.

"Exclamations Always"

Place is a room.

Crying is an action applying to nothing.

Report crying:
    say "You cry for a bit."

Include
(-

[ WailBangSub ;
    BeginAction( (+ the crying action +) , (+ noun +), (+ second noun +));
];

Verb 'wail!' * -> WailBang; 

-) after "Grammar" in "Output.i6t".

Test me with "jump / jump! / wail / wail!". [note that >WAIL doesn't work but >WAIL! does]

Note that neither of the above gets the parser to understand that an exclamation point ends the command, so >WAIL! CRY! won’t be handled the same way that >WAIL. CRY. would be handled under normal parsing rules.

1 Like

Sorry for necroing this thread, but I ran up against this issue recently and there’s not a great deal of information about it.

Is there any problem with approaching it in this way? It felt a little more elegant than some of the other workarounds but I’m a newcomer to Inform.

After reading a command:
	let PlayerCommand be text;
	let PlayerCommand be the player's command;
	replace the regular expression "wail\!" in PlayerCommand with "wail";
	change the text of the player's command to PlayerCommand.

Punctuation Removal (installed with the IDE) is a straightforward way to deal with tasks like this, and it is probably a good fit for most. Still, sometimes authors prefer to avoid dependencies. Or it might be that some find regex easier to read than Inform 6. I don’t see anything wrong with that! I think one thing you might want to consider is stripping exclamation points from all commands. If players try them in one place, they’ll probably try them everywhere.

Regex has a reputation for poor performance in Inform. This substitution won’t hurt anything, but you’ll probably want to keep an eye on things if you’re running through tables or performing multiple matches in succession.

2 Likes

Thanks, that’s really helpful. :slightly_smiling_face:

1 Like