Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(4 edits)

When you click a link in Harlowe 2 the link goes away. Usually what you want. Sometimes annoying. A couple of times I've wanted to make a word clickable, and when the player clicks it, it changes to a new word, but remains clickable. Keep clicking it and it cycles around to new values.

There's already sort of published ways to do this, but it's complex and tricky involving auxillary passages which you sub in with (display:)

So I figured out a way to do it using Harlowe's built in (link-repeat:). Here it is:


At the start, I make an array of colours and set the index to 1. Then, when you click the link, I advance the index (using modulo arithmetic to loop around from 3 to 1) and replace the word.

The trick which makes it work is inside the link-repeat macro. Normally link-repeat just takes a string, when you then have no way to alter except by running a blanket (replace:) on all similar strings.

That would fail for this example. If the dress was "red" and you tried to (replace:"red")[green], you would also change part of the word "bored". And when you tried to change "green", you'd also change the later sentence to read "silver with envy".

So what I do is I smuggle a named hook inside the link by putting it all in quote marks. Now I can change the text of the link by changing the inside of the hook while still leaving the link intact to be cycled.

Here's the source:

{
<!-- Initialise range of colours -->
(set:$colours to (a:"red", "green", "silver"))
(set:$colour_index to 1)
(set:$colour to $colours's $colour_index)
}The dress is (link-repeat:"[$colour]<colourhook|")[{
<!-- Pick new colour, then replace description inside the link. -->
(set:$colour_index to (it % $colours's length) + 1)
(set:$colour to $colours's $colour_index)
(replace:?colourhook)[$colour]
}], you're bored, and you just know it'll make them green with envy. Wanna steal it?

(Please note: I absolutely do endorse stealing dresses. Be smart.)