0 votes
by (260 points)
I'm attempting to use a random event to put blocks of text into a variable, for me to print into a separate passage. It works for most blocks of text, but any time I use paragraph spacing or formatting, it seems to break Twine's ability to save that information to a variable. Is there a way to output the results of my random event WITHOUT making the multi-paragraph item a separate passage?

 

For instance, I use a silently called <<display>> macro to generate the RE in question. This contains a randomly set variable, then a nested if/elseif group to track which number was generated. However, the moment I use a multi-paragraph of text, it breaks. Is there a formatting tag I can use to break up paragraphs? I couldn't find any in the Sugarcube documentation. Otherwise, I have to use a separate passage for scenes larger than a single paragraph, and I don't want to do that if I don't have to.

4 Answers

0 votes
by (68.6k points)
selected by
 
Best answer
You show probably show some examples of what you're talking about.
by (260 points)
The bit I'm doing is contained in a passage where I do all the random event work for the "area" of my life-sim game. It contains a randomly set variable, then an <<if>><<elseif>> tree checking the randomly set variable and assigning a section of text to the $outcome variable. This $outcome variable is then printed in a separate passage. The issue seems to be when I'm assigning a large string of text to that variable.

I'm thinking I'm going to need to break the way I've done it and just do passages for each outcome in my <<if>> tree, instead of the clever way I'd thought to do it.
by (68.6k points)

Most people simply use the <<if>> or <<switch>> macros within the appropriate passages to handle conditional content.  For example:

<<if $aCondition>>
Content if $aCondition is true.
<<elseif $bCondition>>
Content if $aCondition was not true and $bCondition is true.
<<else>>
Content if neither condition was true.
<</if>>

There's no general need to assign content to a variable to be printed in a passage, when you may test the conditions and select the appropriate content within the passage.

 

Beyond that.  While you may use the method described by greyelf, the general solution for embedding line breaks within a string is to use the newline escape ("\n").  For example:

<<set $var to "This is the text of the first paragraph.">>
\<<set $var += "\n\nThis is a second paragraph.">>
\<<set $var += "\n\nThis is a third paragraph.">>
\$var

 

by (260 points)
The reason I was doing it in a separate passage was because it's 5 different entries, and the spacing issues for all the <<if>> conditions eats up quite a bit of space. I wanted to reduce that by using a different passage to do all the logic and just show the outcomes. I think I have a solution now, having the outcomes link to different passages where the random events are displayed. It clutters up the grid, but it'll work.
0 votes
by (1.1k points)
Not sure if I'm quite understanding what you're after, but could you put your desired paragraphs in widgets, and call them in when needed?
by (260 points)
I haven't tried messing with widgets yet. I'm still learning and trying new things. I'm thinking I'm going to end up needing to break the outcomes of my random events tree into their own passages and just suck up the clicks.
0 votes
by (159k points)

There are limits to what can be reasonably stored within a String variable but if you really want to store a large piece of formatted text within one then I suggest you use HTML line-break br elements and paragraph p elements to format the text.

<<set $var to "<p>This is the text of the first paragraph.</p>">>\
<<set $var to $var + "<p>This is the text of the second paragraph, it contains a line-break<br>within the text although technically that does make it no longer a paragraph!</p>">>\
<<print $var>>

notes:
a. The above is not a recommendation on the best way to store large pieces of text within a variable, it's just an example of how to include HTML elements within such text.
b. One of the main points of allowing a story to consist of multiple Passages is so you don't need to store large pieces of text within variables, so doing the above defeats this purpose.

by (260 points)
Thank you for this. Good to know there are bits of HTML calls within the Sugarcube story format.
0 votes
by (6.2k points)

No offence, but for future questions, it would be helpful if you put the story format in the title smiley

by (260 points)
First time I've submitted a question. Thought the tag feature worked that way. I'll keep it in mind for next time.
by (68.6k points)

That is indeed what tags are for.  As long as you use them correctly, and you did, they should mostly be sufficient.  I say mostly, because sometimes the full version of the compiler and/or story format is also handy to know.  You do not need, and probably should not, add that information to the title.

My advice on this topic (copy pasted from elsewhere):

Please tag your questions with the name+major version of both the compiler you're using (e.g. twine1, twine2, tweego1) and story format (e.g. harlowe2, sugarcube2), because it can, and often does, make a difference to the answers you'll receive and how quickly you receive them.  I'd also suggest specifying the full version of each somewhere, either as additional tags (e.g. twine2-1-3, sugarcube2-1-8) or within the post, because that can matter too.

by (159k points)

I personally wouldn't add the name of the story format to the title itself as I believe that it just makes the title longer for no real additional benefit.

I would just add the correct tags to the question so that they can be used to find this question later and maybe add the story format and full version number to the end of the question itself.

eg.
For this particular question I would of added at least the following tags:

twine2 twine2-1-3 sugarcube2 sugarcube2-18 

 ... that way it can be searched by the series and full version number of both the application and story format being used, and maybe the following near the end of the question itself:

Twine v2.1.3 and SugarCube v2.18.0

...