Using @Protect to keep a single flag through UNDO?

I have some text that I want to play the first time the player uses UNDO (introducing a game mechanic like Slouching Towards Bedlam). Currently, every time I UNDO is the first time, because the game doesn’t track the use of UNDO.

How can I use the @Protect opcode to keep track if I’ve ever used UNDO? I don’t care if it’s preserved across saves or not, as it would be fine to repeat the message after saving and restoring.

Here is a simple way. The flag won’t get preserved across RESTORE, although it wouldn’t be hard to make that work too.

[code]Include (-
Array undo_used -> 1;
[ InitUndoFlag; @protect undo_used 1; ];
To set up the undo used flag: (- InitUndoFlag(); -).
When play begins: set up the undo used flag.
To say flag undo as used: (- undo_used->0 = 1; -).
The immediately undo rule response (E) is “[flag undo as used][bracket]Previous turn undone.[close bracket]”.
To decide whether undo has been used: (- (undo_used->0 == 1) -).

Every turn when undo has been used, say “UNDO has been used!”[/code]This reminds me that I wrote an extension to make it easy to save various kinds of state across RESTART, RESTORE, and UNDO, but never finished the documentation and so never uploaded it. I’ll try to do that when I have time.

Since the “immediately undo rule response (E)” prints after the game state has been restored, couldn’t you do away with the @protect entirely?

Oops - you’re right, of course.