All of the main Story Formats that include a History system (like SugarCube & Harlowe) are specifically designed to only update that progress History during the Passage Transition process.
eg. they require Passage transitioning to work correctly.
The main Story Formats are also designed to reprocess the contents of the Passage currently being visited if the web-page is refreshed for any reason, like when a mobile web-browser is given focus after a call is taken or a message/sms is read.
So if you want to create a Passage that tracks dynamic changes made to its HTML structure in reaction to end-user interactions then you need to use something other than (or in conjunction with) the default Story Variable system. And luckily SugarCube includes three functions (memorize(), recall(), and forget()) that can be used to store data in the web-browserās LocalStorage area.
note: Because you didnāt supply any examples of the variables or data youāre using to track the current state of the āPuzzleā I current include that information in my own code examples, so I will just use comments in place of real variables/values. All the following examples are untested, and will be Twee Notation based if they include the contents of more than a single Passage.
1: Initialise the variables being used to track the current state of the āPuzzleā.
Because Story Variables are reset (upon page refresh or Save loading) to the value they had just before the ācurrentā Passage was processed the variable(s) being used to track the current state of your āPuzzleā will need to be initialise before the Passage that contains it is visited. And one place to do that is in the body of the link that leads to that Passage.
Blah blah
<<link "Start Puzzle" "Puzzle">>
/* initialise the puzzle's data structure */
<<set $puzzle to { /* the object properties and default values used */ }>>
<<run memorize('puzzle', $puzzle)>>
<</link>>
2: Load current state of āPuzzleā for each (re)visit to the Passage.
This should be done early in the processing of the Passageās content, so the later content can use that data when displaying the āPuzzleā.
<<set $puzzle to recall('puzzle')>>
/* the code that (re)builds the visualisation of 'puzzle' based on the current state,
3: Persist the new current state each time it changes.
This is best done in the code that gets called when end-user interacts with the āpuzzleā.
note: Because I donāt know how you handle such interactions I will used a basic link to represent them.
<<link "Tile 1">>
/* 1. update the current state of the puzzle. */
<<set $puzzle to { /* the new values */ }>>
/* 2. update the current visualisation of the puzzle. */
<<replace "#puzzle">>/* with something different */<</replace>>
/* 3. persist the current state to memory. */
<<run memorize('puzzle', $puzzle)>>
<</link>>
4: Forget the current state of the āPuzzleā when transitioning to ānextā Passage.
The default maximum size of a web-browserās LocalStorage area is between 2-5 MBs per domain, and depending on the brand of web-browser that 2-5 MBs may need to be shared between all locally opened HTML files. And that same LocalStorage area is also used by Story Formats to store the (slot based) Saves the end-user creates, so cleaning up any old data is a good idea.
One place to do this forgetting is in the body of the link used to exit the āPuzzleā Passage.
<<link "Exit Puzzle" "Some Other Passage">>
<<run forget('puzzle')>>
<</link>>
The following is an example of all of the above put together.
:: Some Passage
Blah blah
<<link "Start Puzzle" "Puzzle">>
/* initialise the puzzle's data structure */
<<set $puzzle to { /* the object properties and default values used */ }>>
<<run memorize('puzzle', $puzzle)>>
<</link>>
:: Puzzle
<<set $puzzle to recall('puzzle')>>
/* 1. determine what to display this time */
/* 2. display it */
<div id="puzzle">
<<link "Tile 1">>
/* 1. determine the new state of the puzzle. */
<<set $puzzle to { /* the new values */ }>>
/* 2. update the current visualisation of the puzzle. */
<<replace "#puzzle">>/* with something different */<</replace>>
/* 3. persist the current state to memory. */
<<run memorize('puzzle', $puzzle)>>
<</link>>
<<link "Tile 2">>
/* 1. determine the new state of the puzzle. */
/* 2. update the current visualisation of the puzzle. */
/* 3. persist the current state to memory. */
<<run memorize('puzzle', $puzzle)>>
<</link>>
</div>
<<link "Exit Puzzle" "Some Other Passage">>
<<run forget('puzzle')>>
<</link>>
:: Some Other Passage
You completed the 'puzzle'.