Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sugarcube, text area variable printing line breaks.

edited July 2015 in Help! with 2.0
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

  • Is this for SugarCube 1.x?


    The basic answer is to use newlines ('\n'). For example:
     <<set $x to "-Line one.\n-Line two.">>
    

    Also. If your code actually looks like the following, then it's probably not doing what you think it's doing.
    <<textarea "$y" $x>>
    <<set $x to $y>>
    
    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:
    <<textarea "$x" $x>>
    

    Attached is a working example.
  • This worked, the only difference is because I am coding this via mac, I have to use \r to work. However, you can use \r\n as that page break so it becomes universal amongst mac and pc.
  • What?

    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).
  • edited July 2015
    I am editing within and outside twine to do some additional things.
  • Then you really shouldn't be using the carriage return (as noted above, Mac OS hasn't used that since OS9, IIRC).

    Anyway, whatever works for you. :)
Sign In or Register to comment.