tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Line continuation with nobr only sometimes works #36

Closed Xetanai closed 4 years ago

Xetanai commented 4 years ago

I'm using SugarCube 2.31.1 and Tweego 2.1.1

I've set nobr globally using Config.passages.nobr = true; and have a widget that I'm trying to use to display the current ingame time.

The widget is below:

<<widget "currenttime">>
    <<if $gameDate.getUTCHours() eq 0>>
        12\
    <<elseif $gameDate.getUTCHours() gt 12>>
        <<print $gameDate.getUTCHours() - 12>>\
    <<else>>
        <<print $gameDate.getUTCHours()>>\
    <</if>>:\
    <<if $gameDate.getUTCMinutes() lt 10>>0<</if>><<print $gameDate.getUTCMinutes()>>\
    <<if $gameDate.getUTCHours() gte 12>>PM<<else>>AM<</if>>\
<</widget>>

Given $gameDate is a JS Date object for 8 AM (The date is irrelevant), the output is 8:\ 00\ AM, meaning that the line continuation marker after the print macro for the hour was parsed properly, and the one after AM, but all others are ignored and output

Other times have no effect and the same line continuation characters are ignored,

tmedwards commented 4 years ago

Any markup that depends on line positioning, line continuations included, is not compatible with the no-break features, which turn sources into a single line.

Xetanai commented 4 years ago

I see. Aside from just building a string inside the widget and printing the result all at once, is there any other way to accomplish this that I'm missing?

Thank you for the swift reply!

tmedwards commented 4 years ago

Not really. Using no-break reduces your options a bit. There are several ways to go about what you're trying to do—e.g., templates or macros—but all of them would end up building a string and then either returning it or rendering it, so they wouldn't be especially different from a widget that did it.

Xetanai commented 4 years ago

Alright, thanks for your help. I'll look into those