"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.

Summary

"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 the assumption that the 1st element in the $choices Array is the currently selected choice.

If the user clicks on the link (created through using the (link:) macro), the $choices array is updated using the (rotated:) macro. This causes the current 1st element to be moved to the end of the array, making the element that was previously 2nd to now be 1st.

At the end of every cycle, the currently selected value is always the 1st element in the $choices array.

Live Example

Download: Live Example

Twee Code

:: StoryTitle
Cycling Choices in Harlowe

:: Start
(set: $choices to (array: "First", "Second", "Third"))
Click options to cycle: [(display: "Cycling")]<choice|
[[Submit|Results]]

:: Cycling
{
    (link: (text: $choices's 1st) )[
        (set: $choices to (rotated: -1, ...$choices))
        (replace: ?choice)[(display: "Cycling")]
    ]
}

:: Results
Selected choice: (print: $choices's 1st)

Download: Twee Code

See Also

Setting and Showing Variables, Modularity

results matching ""

    No results matching ""