Can we print text after saving/restoring a game?

Twine Version: 2, Sugarcube 2.30

I have a situation where you are given a puzzle by some superintelligent beings, and you can save the game if you want. This gives opportunity for meta-humor.

I know in Inform, you can do stuff like

check saving the game: say "You hope they don't catch you doing this!";

check restoring the game: say "You look around, hoping those superintelligent beings didn't detect what you did. They're pretty smart, you know."

But my basic searches at Twinery.org turned up nothing.

Is there a way to do this?

1 Like

You could use the Save API to execute code when saving or loading. The details depend on how you want the message to be shown and how the scene works, but for a super basic implementation:

Save.onSave.add(function (save) {
  alert("You hope they don't catch you doing this!");
});

Save.onLoad.add(function (save) {
  alert("You look around, hoping those superintelligent beings didn't detect what you did. They're pretty smart, you know.");
});

Edit: I just noticed that you’re using version 2.30. The Save Events API was added later, so on that version you’ll need to use the Config API instead. I’d recommend updating, though, it shouldn’t break anything.

4 Likes