How to save state of toggle for future passages

0 votes
asked Jun 6 by natstudent (430 points)
Hi :)

I'm trying to create a simple image overlay character customisation (thank you so much for the advice TheMadExile! I'd just like to know how to save the state of a toggle choice for future passages so that the created avatar will appear?

Thanks a lot!

1 Answer

+1 vote
answered Jun 6 by greyelf (88,870 points)
selected Jun 6 by natstudent
Best answer

You can use a story variables to track the current state of each of your toggles.

1. Initialise the story variables within your projects StoryInit special passage.

note: I'm not sure if your toggles start out as displaying the content or not so I will assure that they do and assign the variable an initial value of true, if they don't then change the initial value to be false.

<<set $background to true>>

2. You can then change your toggle links to flip the associated story variable between true and false whenever they are selected.

<<click "Toggle: Background">>
	<<script>>$('#scene .layer0').toggle()<</script>>
	<<set $background to not $background>>


commented Jun 6 by natstudent (430 points)
That's fantastic, thanks so much for your help greyelf!
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.