Cycle

Advances through a list one element at a time, wrapping back to the start when it reaches the end. Each call returns the next item in sequence, keyed by a slot name so unrelated calls don’t share a cursor.

Category: Sequence Returns: any (matches the element type)

Signature

Cycle(slotKey, list)

The first argument is a slot name: any string. The second is the list to iterate over, either a list literal or a list-typed variable.

Examples

Cycle("dialogue", ("Hello.", "How are you?", "Goodbye."))
                                // returns items in order, wrapping to the start
Cycle("weather", ("rain", "sun", "snow"))
                                // cycles through weather states each call

Notes

Cycle keeps a per-slot cursor that advances by one on every call and wraps at the end of the list. The cursor is captured in save snapshots, so a snapshot-restored game continues from where it left off. It also resets at the start of a new run, so a fresh playthrough always starts each slot from the first item.

An empty list, or a variable holding one, returns an empty string rather than raising an error.

Pick a unique slotKey for each call site that needs an independent cursor. Two Cycle("weather", list) calls in different nodes share the same cursor. Pick and Once share the same slot-key behavior.

For a deterministic random pick from a list instead of sequential cycling, see Pick.

Docs last synced: 2026-07-08
Screenshot viewer