Splitting player input mid-word on special characters

Context: when I’m betatesting a game, I usually put comments-to-the-author in brackets, like:

>[Ha! That was hilarious.]

I have a ‘comment’ command for my testers along those lines:

Commenting is an action out of world applying to one topic.

Report commenting:
	say "Noted.";
	stop the action.

Understand "# [text]" as commenting.  Understand "/ [text]" as commenting.  Understand "'[text]" as commenting.

The problem is that the tester has to put a space in after the ‘comment’ symbol:

># typo: 'rapid'
Noted.

>#typo: 'rapid'
I didn't understand that sentence.

Now, this doesn’t really matter; their comment is still in the transcript. But it would be nice to get it right.

There used to be a LanguageToInformese function where you could mess with things like this; would you still have to descend to I6 to handle this? Or is there an I7 way?

I often rail against the use of “After reading a command”, but this is the sort of thing it’s perfect for. That’s I7’s LanguageToInformese equivalent, and you can use it to insert a space after the first character if it’s punctuation.

3 Likes

Yeah I imagine the problem here is that “Understand ‘#[text]’” can’t distinguish between the # on its own and the # as part of the text. But if it bothers you then you could always do a quick check for the #/etc. after a command to make any necessary changes.

The Garden is a room.

Commenting is an action out of world applying to one topic.

Report commenting:
	say "Noted.";
	stop the action.

Understand "# [text]" as commenting.  Understand "/ [text]" as commenting.

After reading a command when the player's command matches the regular expression "^(\#|\/)\S":
	let T be the "[player's command]";
	replace the regular expression "^(\#|\/)" in T with "\1 ";
	say "(changed to '[T]')";
	change the text of the player's command to T;

(# is unfortunately not considered punctuation for \p, so I manually checked both options there.)

Changing the text of the player’s command is always a bit of a nuclear option. This, however, is indeed one of the best uses for it since you don’t care about any contents if there’s a leading #.

Unfortunately, I cannot get “‘[text]” to work since Inform doesn’t enjoy the quotation mark, seemingly. I don’t believe it worked in the original, either, though?

2 Likes

Unless I’m missing something, I think this version should catch the usual cases:

After reading a command:
	if the player's command matches the regular expression "^(#|/|[']|\*)":
		say "(Noted.)";
		reject the player's command.

The Lab is a room.

(Adapted from example 413, “Alpha”, ch. 20.6, to include the single quotation mark, which isn’t caught by “^\p”.)

2 Likes

While I see /p discussed, it isn’t in these examples unless I’ve missed it! That is required to catch the “[” character, I believe. This is what I’ve seen handed around; it’s a mashup of what’s been posted so far.

lab is a room.

after reading a command:
	if the player's command matches the regular expression "^\p|^<*#+=[']'>":
		say "(noted)[line break]";
		reject the player's command;

Other characters can be added between the < and > symbols if that is desired.

3 Likes
The Garden is a room.

Commenting is an action out of world applying to one topic.

Report commenting:
	say "Noted.";
	stop the action.

Understand "# [text]" as commenting.  Understand "/ [text]" as commenting. Understand "' [text]" as commenting. Understand "* [text]" as commenting.

After reading a command when the player's command matches the regular expression "^(#|/|[']|\*)\S":
	let T be the "[player's command]";
	replace the regular expression "^(#|/|[']|\*)" in T with "\1 ";
	say "(changed to '[T]')";
	change the text of the player's command to T;

Ah! So that does work for “‘“, then. Good to know and appreciated.

(Still using a proper action/not using \p here, but only because that was what was in the original example and I’m not sure if there’s a rule we’re not seeing. Both are still certainly options worth consideration.)

2 Likes

I was just looking this up the other day, the docs say that \p catches . , ! ? - / " : ; ( ) [ ] { }

1 Like

True! I left \p out because I wasn’t sure whether Lucian wanted to include the full range of punctuation, but it can’t hurt to be comprehensive.

1 Like

Yeah, I think your version is actually closest to the original question in both these regards.

2 Likes

I was just keying in on his own practice of using brackets! I have noted that different people prefer different characters, so it is best to cover as much ground as possible.

I am curious about the rule vs rejection question. I would probably use a rule if I wanted to store the comments someplace, for instance

2 Likes

As a side note, I would love it if an upcoming version of Inform included this as a default feature. Dialog has it built-in and it’s very convenient (as a tester) that I don’t have to rely on the author coding it in.

Plus, if it’s a default feature, testers will all come to use the same syntax, because it’s the one the language supports. (In Dialog that’s * as a separate word.)

1 Like

Thanks! This is all great.

I appreciated the ‘reject the player’s command’ method, but in case I wanted to do something with the comments at some point, this is what I ended up with. I did go with the \p, since, like, what else is the player going to mean; I put the regex in a ‘to say’ bit so I could experiment with different ones more easily; and I changed all comments to “# [text]” so I only had to have a single ‘understand X as Y’ line:

Testing is a room.

Commenting is an action out of world applying to one topic.

Report commenting:
	say "Noted: [the topic understood].";
	stop the action.

Understand "# [text]" as commenting.

To say comment_regex:
	say "<\p*#+=[']>"

After reading a command when the player's command matches the regular expression "^([comment_regex] ?)\S":
	let T be the "[player's command]";
	replace the regular expression "^[comment_regex] ?" in T with "# ";
	say "(changed to '[T]')";
	change the text of the player's command to T;
4 Likes

You know, I never thought of putting regex components in text substitutions before. That’s a really smart way to do it. I wish I could do that in Python or JS!

1 Like

Filed!

3 Likes