How to collapse whitespace for multiple links where only one link is conditional

Twine Version: 2.7.1
Harlowe Version: 3.3.7

I’m trying to present a list of links where only one of those links is conditional, governed by a variable:

You and Clop walk down the lawn to the shed. The door is locked with a combination padlock. 

[[Try 1234]]
[[Try 1111]]
(if: $codetoshed is true)[[Try 6391]]
[[Look around back of house->Back of house]]
[[Go to front of house->Look around house]]

If $codetoshed is false, the player sees whitespace in its place. I could move the [[Try 6391]] link to the bottom of the list, avoiding the whitespace issue. But for gameplay purposes I want key navigational links to always appear as the last option.

I’ve tried using {curly brackets}, like so:

{
[[Try 1234]]
[[Try 1111]]
(if: $codetoshed is true)[[Try 6391]]
[[Look around back of house->Back of house]]
[[Go to front of house->Look around house]]
}

But this collapse the line breaks between each link, making all the text squish together. I tried to counter this by adding line breaks at the end of each link, like so:

{
[[Try 1234]]<br/>
[[Try 1111]]<br/>
(if: $codetoshed is true)[[Try 6391]]
[[Look around back of house->Back of house]]<br/>
[[Go to front of house->Look around house]]<br/>
}

This solves for if $codetoshed is false, but if $codetoshed is true it produces a text run-on issue:

Try 1234
Try 1111
Try 6391 Look around back of house
Go to front of house

I’ve tried adding a line break after the conditional, but this adds an unconditional line break (back to the issue I first had at the start). In other words, I can’t attach the line break to the conditional.

Any help on this would be much appreciated. Thanks in advance!

You should be able to do something like the following:

A
(if: …)[B
]C

For example:

You and Clop walk down the lawn to the shed. The door is locked with a combination padlock. 

[[Try 1234]]
[[Try 1111]]
(if: $codetoshed is true)[[[Try 6391]]
][[Look around back of house->Back of house]]
[[Go to front of house->Look around house]]

Note the hook containing the link, which the following link immediately follows.

3 Likes

Change the above conditional line in your Collapsing whitespace markup based example, that included manually added HTML <br> line-break elements in it, to include the Hook that is normally associate with the (if:) macro and place the required <br> in it along with the conditional link …

(if: $codetoshed)[ [[Try 6391]]<br>]

notes:
1: there is no need to use the is comparison operator when evaluating the current true / false state of a Boolean based variable…

<!-- Syntax for checking for Boolean true -->
(if: $codetoshed)[The variable current equals true]

<!-- Syntaxes for checking for Boolean false -->
(if: not $codetoshed)[The variable current equals false]
or
(unless: $codetoshed)[The variable current equals false]

2: A HTML <ul> unorder-list element structure can be used instead of manually added <br> elements.

{
<ul>
	<li>[[Try 1234]]</li>
	<li>[[Try 1111]]</li>
	(if: $codetoshed is true)[<li>[[Try 6391]]</li>]
	<li>[[Look around back of house->Back of house]]</li>
	<li>[[Go to front of house->Look around house]]</li>
</ul>
}

…which has the added advantage of generating HTML that is more Semantica, which can help those using Accessibility tools. CSS can then be applied to the unorder list structure to style its appearance.

4 Likes

Thank you, that worked perfectly!

Thank you for these elegant solutions! I appreciate the additional guidance on eliminating the is comparison operator.