"Cycling Choices": Harlowe (v2.0)

Note: This example is affected by history changes in the story. Undoing or re-doing back to a passage containing this recipe has the potential to change its saved values.


"Cycling Choices" demostrates how to create a 'cycling' effect of different choices through clicking on them.

The 'cycle' starts with the use of the (display:) macro and assumption of $choicesCount beginning at the number 0. It is then increased by one to the value 1 (the first location of an array in Harlowe) and the position of $choices is shown based on this.

If the user clicks on the link (created through using the (link:) and (display:) macros) again, future 'cycles' test if $choicesCount increases beyond the number of values in the $choices array and resets it to 1.

At the end of every 'cycle,' the currently selected value is stored in the variable $cyclingResult for future access and usage.

Live Example

Download: Live Example

Twee Code

:: StoryTitle
Cycling Choices in Harlowe

:: Start
Click options to cycle: (display: "Cycling")

:: Cycling
    (set: $choices to (array: "First", "Second", "Third") )
    (if: $choicesCount >= $choices's length)[(set: $choicesCount to 1)]
    (else:)[(set: $choicesCount to it + 1)]
    (set: $cyclingResult to $choices's $choicesCount)
    (link: (text: $choices's $choicesCount) )[(display: "Cycling")]

:: Results

Download: Twee Code

See Also

Setting and Showing Variables, Modularity

results matching ""

    No results matching ""