Conditional Undo

version 4/140510 by Jesse McGrew

  • Home page
  • Beginning



  • Documentation
    This extension allows more control over the use of UNDO than the standard "Use undo prevention" option. There are three stages where we can intervene in the undo process, and each one can override the previous one:
    1. Use the phrase "prevent undo" in an action. This will prevent that action from being undone. (If we change our minds during action processing, we can say "do not prevent undo".)
        Instead of pushing the red button:
            say "You key in the launch sequence and fire off the nuclear missiles. There's no turning back now.";
            prevent undo.
    2. Write a rule for the "deciding whether the action prevents undo" activity. This activity runs at the end of each turn, and we can say "it does" to prevent undoing the current action, or "it does not" to allow undoing the current action (even if we said "prevent undo" in the action itself).
        Rule for deciding whether the action prevents undo:
            if the player is wearing the time travel anklet, it does not;
            if the player was in the Zone of Permanence, it does.
    3. Write a rule for the "deciding whether to allow undo" activity. This activity runs when the player actually tries to undo. We can say "allow undo" or "deny undo" to make the decision, and again, the decision we make here will override any decision made in stage 1 or 2.
        Rule for deciding whether to allow undo:
            if the turn count is greater than 5
            begin;
                say "Too late for that, buddy.";
                deny undo;
            end if.
    Notice that we printed our own denial message in the above example. The "deciding whether to allow undo" activity is the only place we can do that; if we don't print a message, or if we prevent undo from stage 1 or 2, the player will normally see the default message ("That action cannot be undone"). However, we can write a rule for this activity that detects whether one of the earlier stages has already prevented undo, and prints a custom message if so:
        After attacking someone (called Todd):
            say "[The Todd] will never let you live that down, bro.";
            prevent undo.
        
        Rule for deciding whether to allow undo:
            if undo is prevented, say "You'll just have to deal with the wrath of your enemies."
    CHANGE LOG
    Version 2 added Glulx support.
    Version 3 updates the extension to work under (and require) I7 build 5T18.
    Version 4 updates the extension to work under (and require) I7 build 6L02, and fixes a bug where a "deciding whether the action prevents undo" rule that made no decision would incorrectly prevent undo.