+1 vote
by (1.1k points)
retagged by
Is it possible through java scripting to save a string/information from within a game to local storage which can be retrieved in later sessions?

I want to save something to local storage which can be checked when the game starts, specifically if the player wants to skip introduction and setup. While this could be done with a game save, I worry about all the other baggage the save may carry with it.

1 Answer

0 votes
by (1.1k points)
edited by
And ten seconds later I realized how a saved game could be used in this way... I can use (saved-games:) to check if a specific save file/slot exists, which can toggle the option, without actually loading the save.

A bit bloaty in localstorage compared to a single string, but possible with current harlowe macros.

 

(I didn't mark this as an answered as someone may come along with a much better solution)
by (1.1k points)
With the difficulty in clearing the twine browser storage, testing this for errors is proving to be difficult.
by (1.1k points)

this is what I did,

In the preferences passage:

<tr>
	<td>
	(if: (saved-games:) contains "Skip Intro Slot")[
		(if: (saved-games:)'s "Skip Intro Slot" contains 
			"skipintroduction")[
			(set: $gameShowIntro to false)
			(text-colour: "orange")[Skipping Intro]
			]
		(else-if: (saved-games:)'s "Skip Intro Slot" contains 
			"playitagainsam")[
			(set: $gameShowIntro to true)
			(text-colour: "green")[Play Intro]
			]
		(else:)[(text-colour: "red")[error]]
		]
		(else:)[(text-colour: "yellow")[not set]]
	</td>
	<td>
		Off
	</td>
	<td>
		(if: $gameShowIntro is false)[(text-colour: "orange")[
			on]]
		(else:)[(text-colour: "green")[off]]
			</td>
	<td>
		(link: "")[
		(if: $gameShowIntro is true)[
			(set: $gameShowIntro to false)
			(save-game: "Skip Intro Slot" , "skipintroduction")
			(text-style: "mark")[OFF]
			]
		(else:)[
			(set: $gameShowIntro to true)
			(save-game: "Skip Intro Slot" , "playitagainsam")
			(text-style: "mark")[ON]]
			]
	</td>
</tr>

Then in the launch passage, I have

##Introduction Testing
(if: (saved-games:) contains "Skip Intro Slot")["skip intro slot positive"
	(if: (saved-games:)'s "Skip Intro Slot" contains "skipintroduction")[
		"skip introduction is positive]
		(else-if: (saved-games:)'s "Skip Intro Slot" contains "playitagainsam")[
		"playitagainsam is positive"]
		(else:)[not sure?]
	]
	(else:)[no intro slot?]

(which I'll be doing more with, (: )

...