I have developed a turn-based game in Twine 2.2.1, and Harlowe 2.1.0. It has a rather extensive set of variables, arrays, and datamaps, and I'm running into a peculiar problem with the built-in game save feature.
The game has an eight-slot combined save and load function passage, which lets the user perform either action on the slots as appropriate. Either action pops an 'alert' with confirmation (or error), and the page is redisplayed. A link on the bottom allows the user to proceed when they're finished. The page consists of a set of HTML table cells coded as follows. The $loadOnly flag may be previously set to prevent saving (if the passage is called immediately upon startup, for example). Each occupied slot is labeled with the game 'day', and the character weight (which is important to the game).
<td style='padding:15px'>(if: (saved-games:) contains "A")[(print:(saved-games:)'s "A") <br /><div class="button2">(link: "Load")[(alert: "Game slot 1 Loaded!")(load-game:"A")(goto: "SaveGame")]</div>(if: $loadOnly is 0)[ - <div class=
"button2">(link: "Replace")[(if:(save-game:"A", "Day " + (text:$day) + ", " +(text:(floor: $weight)) + "lbs") )[
(alert: "Game Saved!")
](else: )[
(alert: "Error - Game NOT saved!")
](goto: "SaveGame")]</div>]](elseif: $loadOnly is 0)[
<div class="button2">(link: "Save to slot 1")[(if:(save-game:"A", "Day " + (text:$day) + ", " +(text:(floor: $weight)) + "lbs") )[
(alert: "Game Saved to Slot 1!")
](else: )[
(alert: "Error - Game NOT saved!")
](goto: "SaveGame")]</div>
](else:)[Slot 1 Empty]</td>
The game consists of daily "turns", and can last several hundred days of in-game time. Once the current game reaches longer durations, the chances of a saving error increases. This is an example of a progression from recent testing:
I started out with 8 filled slots from previous games at various stages. I started a new game, and regularly saved to a specific slot (in my case, slot 2). Note that this is with a published HTML file, running in Chrome. (Since testing natively in the Windows client butchers the gamesave/load functionality, and it must be tested live.)
- By about day 400, I hit my first save failure. I was able to replace a *different* slot first, and then replace the original slot immediately after.
- By about day 500, I had to try a couple other slots before I found one that would still allow an overwrite, but then oddly could still jump back and write the original slot as well.
- On day 568, no slots were allowing overwrites. I cleared my session data (and flushed all saves). Once cleared, I could save the game to the first four slots. It failed on the fifth.
- On day 600, after clearing all data again, I could only use three slots before it failed to set the fourth.
In the short term, I suppose I could reduce the number of available slots, or perhaps impose more restrictions on game duration. My suspicion is that the game history array is growing to immense size, and overflowing some kind of session storage limit.
Any thoughts on how I can approach this problem? Thanks in advance.