0 votes
by (160 points)

In SugarCube 2, I want to format a Dungeons & Dragons-style attribute block so that the parenthetical texts announcing the modifiers are flush with each other regardless of whether their respective attributes are 1 or 2 digits. My game is in Courier, so every character is the same size, which means that doing so should be as simple as inserting a single extra space before the parenthetical text corresponding to any attribute that is only 1 digit. My immediate thought was to have an <<if>> macro insert that space whenever the corresponding attribute is lower than 10:

STR <<print $STR>><<if $STR lt 10>> <</if>> (Modifier <<if $STRModifier >= 0>>+<</if>><<print $STRModifier>>)
CON <<print $CON>><<if $CON lt 10>> <</if>> (Modifier <<if $CONModifier >= 0>>+<</if>><<print $CONModifier>>)

--and as you can see, I'd had success doing a similar thing to insert a + sign before non-negative modifiers. Unfortunately, in this case, the extra space seems to just disappear from the outputs. I know that the <<if>> macro itself is working as intended, and I've tried all sorts of variations, but in every case, it seems like SugarCube is trimming the extra whitespace against my wishes. I know that the documentation says that this does not happen. What am I doing wrong?

1 Answer

+1 vote
by (62.7k points)
selected by
Best answer

SugarCube isn't doing anything. Browsers will automatically collapse multiple instances of spaces in a row into one space. You can preserve your spacing by: 

  • Using the html non-breaking space entity (&#160; or &nbsp;). 
  • Preformatting your text with the <pre> element, or wrapping the text in any element with the "white-space: pre;" CSS style rule. 

When the documentation refers to white space, it's generally taking about line breaks, which are not collapsed. 

by (160 points)
This did the trick. Thank you!
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.