Does "UNDO" undo actions that were taken before saving?

If someone restores a saved game, is the UNDO command normally able to undo actions that were taken before saving, or are those not available to undo?

No, it doesn’t seem like you can.

On Z-machine:

An internal saved game for “undo” purposes (if there is one) is not part of the state of play. This is important: if a saved game file also contained the internal saved game at the time of saving, it would be impossible to undo the act of restoration. It also prevents internal saved games from growing larger and larger as they include their predecessors.

Glulx doesn’t call it out explicitly, but the undo stack is not listed as part of the save format, and there’s this note in a different section:

Since saveundo/restoreundo only operate within a single play session, you can rely on the IDs of objects created before the first saveundo. However, if you have created any objects since then, you must iterate and recognize them.

So it looks like the answer is universally no (rather than being interpreter-defined behavior).

1 Like

Thank you!

Speaking more generally, not to Inform, but to save / undo data – I’ve written save / undo systems for a parser in progress – a saved game is basically a snapshot of the current game state, and depending on how undo is handled, it may be essentially the same thing. While it would be possible to save undo information to a saved game file, it could potentially balloon the size of the file, possibly quite tremendously depending on how the world state is handled for undo. So, it’s a deliberate development choice not to do so.

Also, you can generally UNDO a RESTORE. If you could RESTORE an UNDO state, the logic would get messy. :)

To get somewhat tangential from the original question: an autosave system might include the undo stack, along with other non-spec state info (like backscroll). At least, when I’ve implemented autosave, I found that it made more sense to include the undo stack.

(Lectrote’s autosave doesn’t do that, but I might add it.)

This is because autosave – ie, when you relaunch an interpreter that was closed in the middle of a game – is supposed to restore your entire game session, as much as possible. This is different from the player manually creating a save point. (And, at least for Inform games, it’s implemented very differently.)

2 Likes

I do exactly that in mine: UNDOs are part of your session and get saved along with a bunch of stuff not included in a z-machine save when you save your session.

Spatterlight (Mac interpreter) must do this (save some UNDO data), at least for Z-Code games, because when you RESTORE, it plays back the last N commands and responses from the game to them before giving you the prompt. It doesn’t do this with glulx.

-Wade