Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help with making a loop of click and replace

Hello! I am using Harlowe in Twine 2.0.10. I'm also fairly new to Twine so it's possible I am making simple/dumb mistakes.

Here's a simple example sentence: "A Radiohead poster hangs in your room."

I want "Radiohead" to be a link that, when clicked, is replaced by another link ("Gone with the Wind", let's say). I want the user to be able to keep clicking that link and changing it to new things over and over, cycling through a list of 10-20 phrases over and over.

Here is my current solution:
A [Radiohead]<band1| poster hangs in your room.

(click: ?band1)[(replace: ?band1)[ [Gone with the Wind]<band2|]]
(click: ?band2)[(replace: ?band2)[ [Wu-Tang Clan]<band3|]]
(click: ?band3)[(replace: ?band3)[ [Rick and Morty]<band4|]]
(click: ?band4)[(replace: ?band4)[ [Real Madrid]<band5|]]
(click: ?band5)[(replace: ?band5)[ [Marilyn Monroe]<band6|]]
(click: ?band6)[(replace: ?band6)[ [Radiohead]<band1|]]


Problem is, even though Radiohead is re-named to be band1 at the end, it doesn't show up as a link at the end of the loop--it's just plaintext.

I suspected that the program was just running through the code once and giving up. So I tried just copy-pasting the above block over and over and that sort of worked--although, of course, once you run through it as many times as it's there, the same problem arises. This also seemed like a really dumb way to solve the problem.

So my questions are: is there a way to make the program loop back after the last line? Or is there a better way to make the program do what I want it to here?

Comments

  • Your primary issue is that each (click:) macro works exactly once and you burn the one for the band1 hook the first time the link is clicked.

    One way to resolve this would be to do something like the following: (requires Harlowe ≥ v1.2.0)
    {
    (set: $posters to (a: "Radiohead", "Gone with the Wind", "Wu-Tang Clan", "Rick and Morty", "Real Madrid", "Marilyn Monroe"))
    A (link-repeat: "[(print: $posters's 1st)]<band|")[(replace: ?band)[(set: $posters to (rotated: -1, ...$posters))(print: $posters's 1st)]] poster hangs in your room.
    }
    
    Which uses (link-repeat:) to make a link which may be clicked multiple times. The other bits simply declare an array of posters and rotate said array upon clicking the link, replacing the link text with the current 1st element of the array.

    If you wanted to know later on which poster the player chose, it's the 1st index (i.e. $posters's 1st).

    I'm not an expert on Harlowe, so there may be other ways as well.
  • I wondered if there was a way to do this with arrays but could not find a good way. Thanks a bunch for the help!!
  • I wondered if there was a way to do this with arrays but could not find a good way.
    While waiting for the Harlowe documentation to be updated information about the (link-repeat:) and (rotated:) macros can be found on Harlowe's project overview.
Sign In or Register to comment.