Starting over mid-turn with a new player's command (SOLVED)

I have a situation where I want to be able to:

  1. stop the current action
  2. replace the player’s command with an arbitrary string of text
  3. start the turn over and have the game parse this arbitrary string of text as if it had been the player’s command all along

I’m a bit stumped on how to do this. The situation where this comes up occurs after the original command has been parsed and the action-processing rules have begun, so it’s too late to use the “reading the player’s command” activity.

Any ideas?

That’s a nasty case. The answer that best fits the Inform system is “Don’t do it that way.” (It will always be easier to compute an action and try it, rather than re-running the parser.)

I suspect the next-best approach is to end the action and write the new string into the beginning of the command buffer. (Pushing out any existing text, in case the player typed “SNORGWITZEL . GO WEST” and you only want to replace the first part.) This will require some low-level parser hacks, which I do not have on hand.

I guess it’s not something that can be accomplished with “instead of doing anything when…foo the frob instead”?

Scroll Thief does this for the metamagic spells: LLEPS FROTZ BOOK is interpreted as LLEPS, then as the separate command FROTZ BOOK. It takes the topic understood from the previous command, puts it into a global variable, then has a “Rule for reading a command” which checks if that variable is set and pre-empts the player if it is. The Command Modification extension can do this part automatically:

silently execute the command "take apple";

It sounds like you also want to cut off the turn sequence rules when you rewrite the command. Where in the action flow will this be happening? (Before, instead, check?) You could insert a new rule into the turn sequence rules which returns false if “the command override queue is not empty”, but its placement depends on where exactly you’re changing things.

EDIT: For another example of this technique, look at Victor Gijsbers’ “Art of Fugue”. He uses this to make other characters repeat previous commands, reparsing if they’re in a new environment (so “take red” might refer to something different now than it had before).

If you want the text to start in the input buffer, so the player can edit it and add to it, you can use Command Preloading (which is based on some of those low-level input buffer hacks). But it sounds like you want this to happen entirely without the player’s control?

No, because there’s no way to know what frob will be beforehand.

This thread is a different approach to the same problem; maybe I’ll have better luck there.

The earliest place I can put it is at the very beginning of the before rules.

In that case, try this in conjunction with Command Modification.

This is the pre-empt command if necessary rule: if the command override queue is not empty, rule succeeds. The pre-empt command if necessary rule is listed after the generate action rule in the turn sequence rulebook.

This cuts off the rest of the turn after dealing with the action, so before/instead/etc rules will run, but every turn and such will not.

This did it. Thank you for your help!