+1 vote
by (380 points)
:passage 1

<<set $random to random (1, 10)>>
$random

[[passage 2]]

Is it possible to have the first random number generated in passage 1 be rembered when using the back button to go back from passage 2 to passage 1?

1 Answer

0 votes
by (159k points)

The "History Backward" / Undo button moves the story's History system backwards one Moment in time to **before** the previous Passage was processed, and then re-processes that previous Passage again.

This is why the <<set>> macro in "passage 1" is executed again, and why $random can end up with a different value.

If you want $random to equal the same 'random' value after History is wound back from "passage 2" to "passage 1" then you need to change the random number generator system to it's PRNG mode using the State.initPRNG() function within your project's Story Javascript area.

warning: Doing this will make any old saves that you (or the Readers of your story) now invalid, and you will either need to:
a. [simple] Delete those old saves.
b. [advanced] Use a Config.saves.onLoad handler combined with the Config.saves.version property to patch the old saves as they are being loaded.

...