Dialog 'undo'

i’m interested in ‘hijacking’ the undo function, specifically, the undo save state that happens with every turn. I’d like to store a copy of this before the PC goes into a specific area and, when something later happens, yadda yadda yadda, revert back to this state. kind of an automatic save/restore that resurrects the PC.

i see where (save undo $) gets called each turn, but i can’t actually find the predicate anywhere in stdlib in order to divert or ‘hook into’ it with a (my save undo $).

am i crazy or is this special syntax that is somewhere else?

Unfortunately, that’s not currently possible in Dialog. (save undo $) (and its counterpart, (undo)) is a built-in predicate that’s handled at the level of the Z-machine and Å-machine interpreter, which means you can’t really modify its function like this. The Z-machine lets you save an undo state, and restore the most recent undo state…and that’s it. Everything else is handled by the interpreter.

(As a side note, the only game I know which repurposes (save undo $) for something other than normal undo is Forsaken Denizen—which you’ll notice doesn’t allow normal undoing!)

On the Z-machine backend, it would be theoretically possible to make a new (autosave $Filename $ComingBack) predicate that makes an autosave under a particular name. However, this would require an extension to the Dialog compiler (a much smaller ask now than it used to be, admittedly), and it wouldn’t work on Å-machine—and it would depend on having a Z-machine interpreter that supports the “extended save” mechanism. I’ve never used it before, so I don’t know how widespread that is.

1 Like

thanks, that’s kind of what i expected. it’s not a dealbreaker, i was just curious. i can always do this manually if i really need to, although it would easier (and probably much smoother) to just piggy-back off ‘undo’.