This might be a really basic question, but I can’t seem to find anything about it anywhere, so if I’m missing something obvious, I’m sorry.
I want to have a bunch of passage links that each display on their own line, and I want some of these links to show up only if certain conditions are met. So what my markup looks like right now is basically this:
<<if $metAlice === true>>[[Talk to Alice]]<</if>>
<<if $metBob === true>>[[Talk to Bob]]<</if>>
But if the player has met Alice but has not met Bob, this of course displays as:
Talk to Alice
And I find that whitespace pretty unsightly, but I can’t find anything about how to get rid of it, just how to run things all onto one line with backslashes or nobr.
I know I could get around this by formatting the options as “You could talk to Alice, talk to Bob, or go home,” but the options in my actual game are a little wordier than this and I feel that when enough of them are available to the player, it turns into a wall of text that I, at least, find harder to parse. I would really like to be able to have them on separate lines if there’s a way to do that without the whitespace.
<<if $metAlice === true>>[[Talk to Alice]]
<</if>><<if $metBob === true>>[[Talk to Bob]]
That way the line break only occurs if the <<if>> statement is true.
Another way to do it would be to use the backslash “\” at the beginning or end of a line to prevent a line break:
<<if $metAlice === true>>\
[[Talk to Alice]]
<<if $metBob === true>>\
[[Talk to Bob]]
That method does the same thing as the previous example, but it makes the code more readable.
However, sometimes keeping track of where the backslashes go can get messy, in which case you could to this:
<<if $metAlice === true>>
[[Talk to Alice]]<br>
<<if $metBob === true>>
[[Talk to Bob]]<br>
The <<nobr>> macro prevents line breaks from appearing inside that macro, unless you use something like the HTML <br> element to force a line break. Alternately, instead of using <<nobr>>, if you want to do that for a whole passage, you could simply add a “nobr” tag to the passage.
Which technique to use generally depends on how complex the code is, going from least complex with the top example, to most complex with the bottom example.
Thanks! I was going “there must be somewhere I could put the backslashes that would work” but I just could not figure it out. I also didn’t realize that you could put br tags inside of the nobr macro – that honestly seems the easiest method to keep track of.
I’m not quite sure what you mean by “superfluous indentation” there. I’m not aware of any unnecessary indentation in the SugarCube UI, and if you’re talking about my code, that indentation isn’t “superfluous”, it’s there merely as a coding technique to keep track of what “level” of coding scope you’re currently working in, so you don’t criss-cross elements or put code in the wrong scope. (See “Indentation style” and my preferred “One True Brace Style” indentation style.)
If that isn’t what you were talking about, then you’ll need to clarify for me with an example.
I think what they mean is that \ and <<nobr>> only prevent sugarcube from automatically adding <br> on line breaks. It does nothing to remove the leading spaces and tabs, which can sometimes break your formatting.
I admit this “feature” also annoyed me to point that I overrided one of the built in functions to remove all leading spaces. I discussed adding an option to remove the spaces with MadExile, but they seemed against it.