Undoing death: custom message

I’d like to write a custom method for undoing death in my game. I tried using an extension that works very well otherwise but not here. I think I am missing something–maybe a rule to follow–and that undoing an action is different from undoing death.

[code]“undoprev” by Andrew

include undo output control by erik temple.

rm1 is a room.

undo-code is a number that varies.

report undoing an action:
say “Undo-code: [undo-code].”;
if undo-code is 1:
say “You died in in [location of player].”;
else if undo-code is 2:
say “Un-waiting.”;
say “Ok, undoing generically.”;

check waiting:
now undo-code is 2;

chapter dieing

dieing is an action applying to nothing.

understand the command “die” as something new.

understand “die” as dieing.

carry out dieing:
now undo-code is 1;
end the story;
the rule succeeds;

[x me/undo/z/undo/die/undo]

The commands x me.undo.z.undo.die.undo illustrate my test case–but undoing death is the same as undoing X ME. Any suggestions? Thanks!

Did you notice that after doing ‘z’ and then ‘undo’, the undo code reported by the undo was not 2, but still 0?

What’s going on is that UNDO basically erases everything that happened since the previous move. So player types WAIT and code is set to 2. Then player types UNDO, and the business of them typing ‘WAIT’ and the code being set to 2 is wiped from existence as we roll back to back to before that happened. Then the undo output reports back to you on the state of the undo code now, and it’s 0, as it was before WAIT was typed.

I imagine you’d have to use a hook or variable that was coded as part of the UNDO code (the way Erik’s code hooks in there) if it was going to have a shot at being preserved through the act of undoing.

Or you can do what I did when faced with this problem and write a disk file.

The one thing the game can detect after an undo happens is that it did happen. Any other regular variables that were interfered with during the undone turn will have reverted to their previous state. So what I do is - if I want to take a particlar action after an undo at a particular point, I write a disk file with a flag as we go into the undo. Then after an undo has occurred, the game can check the disk file (which was spared the erasure of the whole turn of game content) and then respond to any particular flag it finds in there.


Thanks! That should be sufficient for what I want to do. The player only needs to know once. While it seems like overkill to have one file for a single boolean, it is a good solution that means I don’t need to delve into the mysteries of I6.

FWIW, the non-file I6 solution is just this:[code]Section “Setup”

Include (-
Array have_died_flag --> 1;
-) after “Definitions.i6t”.
To protect the have-died flag from undo: (- @protect have_died_flag 4; -).
To decide whether the have-died flag is (T - a truth state): (- (have_died_flag–>0 == {T}) -).
To --/-- now the have-died flag is (T - a truth state): (- have_died_flag–>0 = {T}; -).

When play begins:
now the have-died flag is false;
protect the have-died flag from undo.

Section “Demo”

There is a room.

Instead of jumping:
now the have-died flag is whether or not the have-died flag is false;
showme whether or not the have-died flag is true.
Instead of singing:
showme whether or not the have-died flag is true.

[Test me with “sing / undo / sing / jump / undo / undo / sing”.] [Tests can’t contain “undo”, so such commands must be run manually.][/code]

This works great for my game! Thanks so much.

(small voice) but the sample doesn’t work and I’m not sure why. I cut and pasted to my game, and it was okay. But to a new project, compiling gave…

Inform 6.32 for Win32 (18th November 2010)
auto.inf(10712): Error: Expected an opcode name but found protect


Compiled with 1 error and 1401 suppressed warnings (no output)

Compiler finished with code 1

Usually it’s the other way around–I need to modify my own code–but anyone have any ideas? This is such a neat bit of code that I’d like the next person to be able to appropriate it, no worries.

Sounds like your new project is compiling to the Z-Machine (probably z5), not Glulx. The Z-Machine and Glulx have completely different sets of opcodes, and @protect is only available in Glulx.

Urrg. Thank you. Now you mention it, I should have seen that. I’ve caught that error before in I7, and for others too…

Well, I got more learning out of this I6 than I thought I would, so thanks again, people.

To simplify the code slightly, couldn’t you use “the have-died flag translates as (- have_died_flag–>0 -)”?

Try it and let us know.