Howdy, Stranger!

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

Cycling between options using the Harlowe (click-replace) macro

Hey all. I'm trying to allow players to choose a gender. Basically, what I've got is something to the effect of:

You're a dude.(click-replace: "dude")[(set: $gender to 'woman')lady]

What I'd like to do, and what I can't figure out how to do, is allow players to click on "lady," and thereby set the gender to 'man.' Any ideas?

Comments

  • Hi,
    This might not be the best way but you could do something like this:

    -set up two passages one for MALE and one for FEMALE and make MALE the starting passage.

    - in the MALE passage try this:
    (set: $gender to "male" )Gender: (print: $gender)
    
    You're a dude.
    (click: "dude")[(set: $gender to "female")(go-to: "female")]
    

    and in the FEMALE passage, this:
    Gender: (print: $gender)
    
    You're a lady.
    (click: "lady")[(set: $gender to 'male') (go-to: "male")]
    

    This allows you to keep cycling between the two options. Hope that helps :)
  • Normally when people want a Cycling Link in Harlowe I would suggest using Furkle's Cycling Link addon but in your case you want the $variable to store a different value to what is being shown to the Reader.

    The following solution uses a child passage to handle the logic required to display the correct option to the Reader, to update the $gender variable and to (re-)attach the click event.

    1. Add the following to the passage you want the choice to appear in:
    (set: $gender to "man")
    
    You're a |gender>[(display: "Choose Gender")]
    
    [[Result]]
    
    ... the Result markup link is only needed to check the value of the variable.

    2. Create a Choose Gender passage and add the following to it, this is the child logic passage:
    (replace: ?gender)[(if: $gender is "man")[dude](else:)[lady]]
    (click: ?gender)[
    	(if: $gender is "man")[(set: $gender to "woman")]
    	(else:)[(set: $gender to "man")]
    	(display: "Choose Gender")
    ]
    

    3. Add the following to the auto-created Result passage:
    gender: $gender
    
  • Is there anyway to change this so that it works for more than two options/variables? For example, by using if-else statements or something similar?
Sign In or Register to comment.