+1 vote
asked by (380 points)
:passage 1

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

[[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
answered by (132k 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.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.