Remember Character Bios and Endings between restarts

0 votes
asked May 10 by HawkZombie (160 points)
edited May 10 by HawkZombie

Ok, so in my game I am creating, I want to have Character Bios, as well as an Endings list that are both unlocked as you either click certain links or reach certain passages. I was trying to use the <<remember>> macro for Sugar Cube 2, but it's not working.

What I do currently in my StoryInit panel:

<<set $richard to "????">>

Now, when I reach a passage where I link to the character bio, I have this on the bio page:

<<remember $richard = "[[Dr. Richard Forth|Dr. Richard Forth]]">>

This turns the ???? to Dr. Richard Forth, and everything works great...until I restart the game. Then it defaults back to ????.

Now, when I remove the first <<set>> from the StoryInit, it shows up as the variable ($richard) in the Character Bios panel (ugly :P) but then when I hit the one passage with the <<remember>>, it remembers it forever.

Basically, I want to have a variable be one thing, then forever change into another (persist through playthroughs), once unlocked. Is this possible?

1 Answer

+1 vote
answered May 10 by idling (10,470 points)
selected May 10 by HawkZombie
 
Best answer

Try this:

<<if ndef $richard>>
    <<set $richard to "????">>
<</if>>

 

commented May 10 by HawkZombie (160 points)
YES! This works wonderfully. Thank you!!
commented May 11 by Akjosch (6,240 points)

The typical way to write "set a variable to a new value unless it's already a (truth-y) value" in JavaScript - and by extension, Sugarcube - is a bit shorter:

<<set $richard = $richard || "????">>

Not that there's anything wrong with the initial answer, of course.

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.
...