Writing variable value as plain text

Hi, beginner here, so please bear with me. I’m writing an open-ended exploration game in Sugarcube that lets the player keep a journal of the things they discover using a textarea macro. Right now, I’m trying to use a variable ($DailyJournal) to contain the last journal entry that the player wrote, then using a link macro to append that variable (plus html formatting) to a second variable, $GlobalJournal, which contains all of the journal entries the player has written. In turn, I’m passing that variable to the div containing the journal.

Unfortunately, instead of getting the journal entries the player has written in order, I just get whatever the current value of $DailyJournal is, duplicated x however many entries the player has written. Is there a way to append the current value of a variable to another variable as an unchanging, static string? If not, is there a better way to do this?

Code follows. Thanks!

::StoryInit::

<<set $DailyJournal to ''>>

<<set $GlobalJournal to ''>>

<<set $DiscoveryName to ''>>

<<set $Discovery to ''>>


::Cabin::

You're sitting at your cabin, dreaming of adventure. What do you do?

[[Read your journal|Journal]]

[[Go have an adventure!|Adventure]]


::Journal::

You take your journal down off the shelf and open it.

<div id="MyJournal">My Journal:

$GlobalJournal</div>

[[Back|Cabin]]

::Adventure::

<<silently>><<set $Discovery = either("mountain","forest","sea","cave")>><</silently>>
After a week of exploring, you discover a new $Discovery. 

What will you name it?

<<textbox "$DiscoveryName" null "Writing">>

[[Continue|Writing]]

::Writing::

Write about your adventure in your journal. How did you discover $DiscoveryName?

<<textarea "$DailyJournal" null "Cabin">>

<<link "Now back to your cabin" "Cabin">><<set $GlobalJournal += "<h2>$DiscoveryName</h2><br>$DailyJournal<br>">><</link>>

That’s because you’re storing the string “$DailyJournal” in your $GlobalJournal. You want to take that out of the quotes so it adds the current value.

<<set $GlobalJournal += "<h2>"+$DiscoveryName+"</h2><br>"+$DailyJournal+"<br>">>
1 Like

In addition to what Josh said, in the “Writing” passage you’re using a <<textarea>> macro, which doesn’t support a passage parameter. You should probably change that line to this:

<<textarea "$DailyJournal" "">>

As things are it won’t cause a problem, but it could be a bit confusing if you’re reading the code there and expect the “Cabin” parameter to do something.

Have fun! :slight_smile:

@descentmetal
RE: The Passage names in your TWEE Notation based Passage definitions.

You are adding unnecessary (and potentially invalid based on your links) full-colons at the end your passage names, the first line of the Passage definitions should be as follows

:: StoryInit

:: Cabin

:: Journal

:: Adventure

:: Writing

Thanks so much! This did the trick.