How can I show a link text indefinetely of it's chosen or not?

So I want to achieve a class selection screen, player can chose from 3 classes, so far I only wrote warrior, however when I click the link to set class to warrior link disappears and can not be selected again. What I’m wishing to create is to make the link always be there, if warrior is chosen as class I just want to change it’s color, here is the code:

(set: $class to 'none')

Class:

	{(loop:)
    	[(if:$class is 'warrior')
    		[(text-colour:blue)
    			[(link:'Warrior')]
    		]
		(else:)
    	[(text-colour:white)
    		[(link:'Warrior')
    			[(set: $class to 'warrior')]
    		]
    	]
    ]
    }
1 Like

The following is an example of one way to implement a group of togglable links, where only one of the links can be actively selected at any time, and where selecting the “active” link will cause it to become “inactive” again.

The example uses a Named Hook combined with the (rerun:) macro to recreate all the links within the group whenever one of those links is selected.

(set: $class to 'none')

Class:
|classes>[{
	(if: $class is 'warrior')[
		(text-colour: blue)[
			(link: 'Warrior')[
				(set: $class to 'none')
				(rerun: ?classes)
			]
		]
	]
	(else:)[
		(text-colour: white)[
			(link: 'Warrior')[
				(set: $class to 'warrior')
				(rerun: ?classes)
			]
		]
	]
	<br>
	(if: $class is 'thief')[
		(text-colour: blue)[
			(link: 'Thief')[
				(set: $class to 'none')
				(rerun: ?classes)
			]
		]
	]
	(else:)[
		(text-colour: white)[
			(link: 'Thief')[
				(set: $class to 'thief')
				(rerun: ?classes)
			]
		]
	]
}]
2 Likes

Cool! I have further questions though, what are the | and > in |classes>. What is the reasoning behind the ? in ?classes and what is <br> I like to understand things before doing them.

1 Like

The |hookname>[] syntax creates a named hook called “hookname”. A named hook is an area of the passage that you can target with macros. The ?hookname syntax is how you target a hook.

You can also use |hookname)[] to make a hook that starts invisible (e.g. for (show:)) and put the hookname at the end with []<hookname|

<br> is a standard HTML tag that creates a line break.

2 Likes

I think you meant to write |hookname)[] as your example of a Hidden Hook:slight_smile:

2 Likes

I supplied a link to the Named Hook markup documentation in my earlier reply to you, which explains the syntax used to define a Hook that has a Name.

That is the sigil used by Harlowe to distinguish a HookName reference from either a Story $variable or a Temporary _variable reference. And a HookName reference is how you indicate to any macro that supports such (like (show:) or (change:)) which Hook to apply their behaviour / effect to.

That is the element used to represent a line-break in HTML, and that is the element that all the line-breaks within your Passage content is automatically converted into when that Passage is processed.

eg. If a Passage contained the following content…

This is the 1st line of text in the Passage...

This is the 2nd line of text in the Passage...

…then the HTML structure that would be generated when that Passage is visited would look something like…

This is the 1st line of text in the Passage...
<br>
<br>
This is the 2nd line of text in the Passage...

…after the line-breaks in the Passage content where converted.

As to why I manually used a <br> element in the solution I supplied, that was because I used Collapsing whitespace markup { } to supress the addition line-breaks I added while formatting that code so it was (in my mind) more readable, which resulted in the two “togglable” links being shown on the same line.

I used the fact that Collapsing whitespace markup doesn’t supress manually placed <br> elements to allow me to force the two “togglable” links to be on separate lines again, like your original example suggested they should/would be.

1 Like

cough … quite correct

1 Like