Hey,
I am making a story in which a Journal is consistently updated throughout automatically. However, I also want to give the option for the user to change the Journal at any point in time to fit their needs.
What I mean to do is for the user to see all of the journal which has line breaks and then edit them in the text area (without seeing the line breaks).
So, as of right now the lines of codes read:
<<set $x to "-Line one.<br />-Line two.">>
When printed, <<print $x>> reads:
-Line one.
-Line two.
However, when I make the textarea:
<<textarea "$y" $x>>
<<set $x to $y>>
The text area box shows:
-Line one.<br />-Linetwo.
I have tried editing the original set $x to something like
<<set $x to "-Line one.
-Line two.">>
but I just get an error.
Furthermore, If a user uses the textarea box to edit $x and writes:
-Line one.
-Line two.
After submitting, the $x does not output breaks in the text area.
Is there anyway to make a variable with line breaks in passages that does not have to include markup.
Comments
The basic answer is to use newlines ('\n'). For example:
Also. If your code actually looks like the following, then it's probably not doing what you think it's doing. The <<set>>, directly following the <<textarea>>, isn't setting $x to the edited $y, it's setting it to the $y as it is after the <<textarea>> sets it to the default you supplied, which is $x (so you're simply setting $x to $x in a round-about way). This all happens when the passage is rendered, long before the player has a chance to edit anything.
You don't need to do that anyway, simply use $x for both arguments, like so:
Attached is a working example.
Mac OS hasn't used the carriage return ('\r') as it's line termination character since the first version of OS X (and that's been a while). Mac OS X uses the UNIX line termination character, the line feed ('\n'; a.k.a. newline). That said, it's largely irrelevant, unless you're editing the stories outside of Twine 2.
Are you using the browser-based version of Twine 2 in Safari or something?
Regardless, I believe Twine 2 normalizes line termination, so you could use the carriage return if you really wanted, but you should not need to (and, really, just plain shouldn't).
Anyway, whatever works for you.