Howdy, Stranger!

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

cycling link help?

Hello! I am brand new to this whole thing, and I've been hoping to make an on-page multiple choice type thing, which I've seen done with cycling links which can apparently be done with sugarcube, but I'm using harlowe currently, and am fairly clueless!

I found this thread 2.0 cycling typeerror problem
which describes this code
(set: $cycle to 0)

You can't accept second place! You're no |phrase>[short-nosed horse!] It's back to training for you!
(click-replace: ?phrase)[(set: $cycle to (it + 1) % 3) (if: $cycle is 0)[short-nosed horse!](else-if: $cycle is 1)[silver athlete!](else-if: $cycle is 2)[partner to greatness!]]

but when I try it, it's not a repeatable action, I just always get the second choice and then it's no longer a link.

any help on either fixing the code to be repeatable?

Comments

  • edited May 2015
    Sensor macros like (click:) (with hook) and (link:), and the sensor/changer combo macros like (click-replace:) are designed to be non-repeatable. So if you want one to be be repeatable you have to re-attache the sensor macro.

    The following example consists of two passages, I named them Main & Logic but you can name they whatever you like.

    Main - contains the basic text with a hook and the main (click-replace:) macro:
    (set: $cycle to 0)
    
    You can't accept second place! You're no |phrase>[short-nosed horse!] It's back to training for you!
    (click-replace: ?phrase)[(display: "Logic")]
    

    Logic - contains the logic to work out what to display in the hook based on $cycle as well as the re-attaching (click-replace:) macro:
    (set: $cycle to (it + 1) % 3)(if: $cycle is 0)[short-nosed horse!](else-if: $cycle is 1)[silver athlete!](else-if: $cycle is 2)[partner to greatness!](click-replace: ?phrase)[(display: "Logic")]
    
    note: the re-attaching (click-replace:) macro is exactly like the main (click-replace:) macro.

    The follows is the above re-formated to make it easier to read:
    (set: $cycle to (it + 1) % 3)
    (if: $cycle is 0)[short-nosed horse!]
    (else-if: $cycle is 1)[silver athlete!]
    (else-if: $cycle is 2)[partner to greatness!]
    (click-replace: ?phrase)[(display: "Logic")]
    
  • edited June 2015
    "It"...interesting property, I am guessing it means the current value of $cycle here.

    I like having sample recipe code for stuff, it makes it a lot easier to figure out how to think in this format.
Sign In or Register to comment.