Undo as a command

undo looks to be implemented, not as a command, but even more fundamentally. In the Inform world, it is possible to control when undo is allowed, and that’s something I would like to have control over as well. If there was a command [undo] it would be possible to control under which circumstances undo was allowed.

In the Sand-Dancer game, I want to be able to prevent undo after smoke cigarette (which is actually the hint system inside Sand-Dander).

1 Like

Good point! I’ll figure out a way to let the story control when undo is allowed. Either by reusing the action-handling interface, or in some custom way.

Undo needs to be handled specially in the parser because the engine needs to check for “undo” before saving the current state in undo-memory, which in turn happens before dealing with the ordinary commands. If undo were implemented as an ordinary command, the engine would have to rewind twice: Once to revert back to before the “undo” itself, and then a second time to actually take back a move. But there is no way in the Z-machine to pass information back in time, apart from the built-in boolean return value from save-undo that informs the caller that we’re coming back from the future. So after reverting once, there’s no way to know if a second undo is due or not.

There are three other special cases in the parser: “again”, “g”, and “oops”.

1 Like

There’s some prior art for this in Inform7 AFAIK.

But if you create a situation where the story would not let you ‘undo’, you will also block all undos to before that point in the story, won’t you?

There’s an important question of game design here, for sure. I would not recommend messing with the undo feature without a very good reason. But I think the language should support it.

By the way, I like the comparison between hints and cigarette smoking. In desperate times, there is perhaps a temptation, but the player will resist for a long time. They might feel bad about it afterwards. But the second time, there is less resistance. And then it all goes downhill very quickly. And there is no undo.

Usability versus gritty realism. That’s for the author to decide, not me.

But the player decides whether to keep playing the game. Don’t forget that part. :)

Skipping past the question of whether it’s a good idea – you could omit the save_undo step, rather than blocking the UNDO command. That way, UNDO still works but it jumps back to the previous scene. This makes sense for some story design, particularly if you have a randomized challenge or password.

Inform is also structured with UNDO handled specially in the parser, for the same reason as Dialog. There is no “undoing action” in the standard action list. The UNDO-control extension therefore needs to have a special rulebook.

(At one point I was considering an extension to Glulx to add an opcode for “discard the most recent undo state.” This would permit simpler UNDO customization, at the cost of some wasted memory – some parser paths would create an UNDO state and then immediately throw it away. Is this still an attractive idea? Doesn’t help Z-code games, obviously.)

In one exercise from the book (“Creating Interactive Fiction with Inform7”) it gets to the point that once you start smoking, the PC may start doing so spontaneously.

This is now implemented in library version 0.38.