Thoughts on 'undo'

I've been thinking a little about the way 'undo' works.

First off, I'm wondering if you might sometimes want a menu (the ShowMenu kind) to be undone. I'm sure there are circumstances where you might want a menu that the player can choose from, and then if they enter "undo" they would want to go back to the menu.

So how about something like this:

<function name="AllowUndo" parameters="title, params, script">
  game.undoabletitle = title
  game.undoablescript = script
  game.undoableparams = params
  start transaction (game.pov.currentcommand)
  invoke (script, params)
  game.undoabletitle = null
  game.undoablescript = null
  game.undoableparams = null

<function name="UndoableMenu" parameters="title, options, cancel, script">
  params = QuickParams ("title", title, "options", options, "cancel", cancel)
  dictionary add (params, "script", script)
  AllowUndo ("menu choice: "+title, params) {
    ShowMenu (title, options, cancel, script)

<command name="undo">
  <pattern type="string">[undo]</pattern>
    // should be a test here to see if the game has started
    game.suppressturnscripts = true
    if (GetBoolean (game, "gridmap")){
      Grid_DrawPlayerInRoom (game.pov.parent)
    if (HasScript (game, "undoablescript")) {
      if (HasString (game, "undoabletitle")) {
        msg ("Undone "+game.undoabletitle)
      invoke (game.undoablescript, game.undoableparams)
      game.undoabletitle = null
      game.undoablescript = null
      game.undoableparams = null
    else if (HasString (game.pov, "currentcommand")) {
      msg ("Undoing command: " + game.pov.currentcommand)

The function AllowUndo is basically invoke, but means that the next use of "undo" will go back to the point immediately before running that script.
UndoableMenu takes the same parameters as ShowMenu, but if the player enters "undo" afterwards, it will redisplay the menu.

This modified 'undo' command also makes sure to update the location bar at the top of the screen (which the current one doesn't do), and displays "Undoing command: go north" or "Undoing menu: What would you like to buy?" or similar, so it's easier for the player to know what they're doing.

I think there should be a better way to do this, but I'm having trouble thinking of it. This is a rough first attempt.

Log in to post a reply.