I have a particular passage (where the user rolls the dice) that I don’t want the player to be able to scroll back to once they have visited that passage.
Does anyone know how to code it to disable a user revisiting a particular Twine passage?
Thanks in advance
You have a few options. In order of desirability:
1. Limit the history, so undoing is not possible (most)
If you don’t mind disallowing the player from undoing history at all, then the easiest and best solution would be to limit the history to a single moment via the
Config.history.maxStates = 1;
2. Move the number generation
You could simply move the number generation a passage or two further back from where it appears to happen. A bit of slight of hand.
For example: (in Twee notation)
Text, more text…
<<link [[To B!->B]]
/* Roll 3d6 a passage earlier than it seems. */
<<set $roll to random(1, 6) + random(1, 6) + random(1, 6)>>
Blah, blah, blah…
[[Roll the dice!->C]] /* No rolling actually happens here. */
You rolled a $roll!
3. Use the built-in seedable PRNG (least)
SugarCube includes a seedable PRNG that, when enabled, will produce pseudorandom results based on a seed that doesn’t change for the entirety of a playthrough. Meaning that for any playthrough, a particular pull will always yield the same result—i.e., undoing the history to retry a roll always yields the same number(s), defeating roll scumming.
You enable the seedable PRNG via the
WARNING: The seedable PRNG only affects the
Thanks for that! For various reasons, I chose option 3 which seems to do exactly what you describe.
One question, I take it this will not affect future rolls - i.e. it won’t yield the same roll results later in the game?
If affects all pseudorandom number generation and the same value could be generated down the line, because it’s (pseudo)random, but it wouldn’t be the same result.
To be clear. If you meant will it will always generate the same number for the same pull count in future playthroughs, then the answer is no, as long as the seed differs—which it will if you use it as shown in my above example.
It only yields the same result for the same pull count in two situations:
- You specified a seed, rather than letting it automatically seed itself. Don’t do that.
- It’s the same pull count in the same playthrough—e.g., the player keeps undoing and replaying a moment in an attempt to get a different outcome.
The latter situation is why you’re using it, so players can’t roll-scum.
Basically, it does what you want and nothing more.