Weird title, I know. I just finished undo/redo for a little parser IF thing and the approach I ended up with doesn’t feel like a typical undo setup, but I wonder if it’s normal for IF.
Basically it works like this: the internal state is saved (almost) every time the player inputs something, in a ring buffer. So far this could be called a state-based approach; we can use “undo” to reload an old state.
The problem is that there should be some kind of output to let the user know where they are. So in addition to saving the old states, the player’s commands are saved in another ring buffer. To undo an action, we can load the state before the previous state and then issue the command that was used to get from there to the following state (command approach). Same with redo; always load the state prior to the one we want, and re-issue the command. This way the player sees the same output they saw before, and knows where they are in the undo history.
This feels a little strange, but I’m wondering if it’s normal for IF interpreters. It could be extended pretty easily to only save the state every 10 turns or so, with several commands stored in between. Then you’d rewind to the appropriate saved state and execute however many commands you need to get to the desired state, hiding the output from all but the last command. That could allow for pretty large undo stacks without hogging too much memory… is an approach like that normal/expected?
I suppose drawbacks of “extended” version would be taking slightly longer to execute more commands, added complexity, and the fact that undo history size would fluctuate between, say, 90 and 100 (for 10 states with 10 commands in between each).
Another thing I’m wondering is whether it would be crazy to ditch all the yes/no prompts and maintain the undo stack in atypical places, like after restoring, restarting, or quitting the game (assuming “quit” leaves you at some kind of title screen where you can still restore/restart). I feel like this was becoming the norm for UI a while back – just do stuff without double-checking and let the user undo it if they want, like deleting an email in gmail. I’m not sure if it ever really caught on, though.