Disabling multiple commands per input redux

This has been asked a few times over the years, though I think it’s been a while. I also don’t think I reach the skill floor for some of those discussions, so I decided to make a new topic.

Is there a reasonably safe way to disable multiple commands per input, i.e., take ball.drop ball? I could probably get away with a draconian “after reading a command” rule (it’s a limited parser situation) and reject everything, but thought I’d ask around first.

When you say ‘reject everything’, do you mean, reject the whole line, not keeping the first valid part of it if someone tried to chain commands together? Or do you mean something else?

In my WIP I am rejecting the whole line. (I’m using Unified Glulx Input, where the input type can change (from a string to a single letter, for instance) between moves, and the chained commands stuff in Inform isn’t compatible with this.) I suppose chaining is not something a player will try repeatedly after the game tells them they can’t do it.

My approach is that I reject lines containing:

  • commas anywhere
  • the word “then” with a space on both sides
  • more than one period
  • one period that isn’t the last character in the line

I’ll just paste the guts of this ‘reject all’ code here in case you want to use it:

After reading a command:
	let T be the substituted form of "[the player's command]";
	if T matches the text ".":
		let PERIODALERT be true;
		if T matches the regular expression "\.$":[this checks if a period as the last character. In which case we need to do extra checking:]
			if (number of times T matches the text ".") is 1:
				now PERIODALERT is false;
			if PERIODALERT is true:
				say "Chained command rejection.";
				reject the player’s command;
	if T matches the text "," or T matches the text " then ":
		say "Chained command rejection.";
		reject the player’s command;

I don’t know if there’s an easier way. Either there is, or I couldn’t use it because of the tech situation I’m in.

-Wade

2 Likes

This would be great for my situation. Time just doesn’t work the way Inform expects it to. I didn’t know if there was some i6 dark sorcery out there, but this is a good answer. And, since my understanding of regex is really, really bad, this code is a lifesaver! I’m curious about other possibilities academically, but this is a solved problem. Thanks Wade! (for anyone finding this, I had to tweak an indent in my project. This is how it looks in my game:

After reading a command:
	let T be the substituted form of "[the player's command]";
	say t;
	if T matches the text ".":
		let PERIODALERT be true;
		if T matches the regular expression "\.$":[this checks if a period as the last character. In which case we need to do extra checking:]
			if (number of times T matches the text ".") is 1:
				now PERIODALERT is false;
		if PERIODALERT is true:
			say "Chained command rejection.";
			reject the player’s command;
	if T matches the text "," or T matches the text " then ":
		say "Chained command rejection.";
		reject the player’s command;
3 Likes

As far as I6 goes, you need to replace the constants THEN1__WD, THEN2__WD, and THEN3__WD, which are all the synonyms for “then”. How you do this will be different in Inform 10 than in previous editions.