Skip to main content

Wheel Spin

The maths half of a bonus wheel: picks one segment by weight from the seeds and reports where the wheel must stop. Maths node that also compiles to the RGS.

Segments is an array of labels (strings or numbers) or of { label, weight, prize } objects; JSON text is accepted. Weights (optional) and Prizes (optional) are parallel arrays that override per index, and the wheel has as many segments as the longest of the three. A segment with no weight anywhere weighs 1, a bare numeric segment doubles as its own prize when Prizes (optional) is empty, and a missing label becomes the 1-based position.

Wire Seeds from ISAAC Random Number Array Generator array and fire Do once per wheel award, after the seeds are in. The node draws one weighted index from a Park-Miller generator seeded with Seeds[0], so the same seed lands the same segment in the editor preview and on the RGS. Stateless: nothing is kept between awards.

Segment Index is 0-based. Angle (deg) is the centre of the winning segment in degrees clockwise from 12 o'clock: segment i spans [i, i + 1) * 360 / N and its centre is (i + 0.5) * 360 / N; Sweep (deg) is 360 / N. Prize is the raw prize as given, Prize Value its numeric form (0 when it is not numeric) and Segments (normalised) the full [{ label, weight, prize }] list for drawing the disc.

The visual half is pixi.Wheel: wire Segment Index into its targetIndex, fire its spinTo, and pay from its onSpinComplete rather than from this node's Done, or the win shows before the wheel has stopped. Unseeded, with an empty segment list or with all-zero weights, the node fails closed: it logs the reason, writes it to inspect data, empties every output and still fires Done.

Inputs​

Parameters​

DataDescription
Segments (array)Labels (strings or numbers) or { label, weight, prize } objects, one per segment; array or JSON text. Default [].
Weights (optional) (array)Optional per-index weights overriding the segments' own; a segment with no weight weighs 1 and 0 excludes it.
Prizes (optional) (array)Optional per-index prizes overriding the segments' own; numbers or strings.
Seeds (array)Random seeds, wired from ISAAC Random Number Array Generator array. Required; the node refuses to run unseeded.

Actions​

SignalDescription
DoRuns the node.

Outputs​

Events​

SignalDescription
DoneFires when the node has finished, on success and failure alike.

Results​

DataDescription
Segment Index (number)0-based index of the winning segment; wire into pixi.Wheel targetIndex. 0 after a failure.
Prize (any)The winning segment's prize as given, number or string; null after a failure.
Prize Value (number)The prize as a number; 0 when it is not numeric.
Label (string)The winning segment's label.
Angle (deg) (number)Centre of the winning segment in degrees clockwise from 12 o'clock, (index + 0.5) * sweep.
Sweep (deg) (number)Degrees per segment, 360 / segmentCount.
Segment Count (number)Number of segments after normalisation.
Segments (normalised) (array)The normalised [{ label, weight, prize }] list actually spun, handy for drawing the disc.

Usage​

  1. Wire ISAAC Random Number Array Generator array into Seeds.
  2. Provide Segments, plus Weights (optional) and Prizes (optional) when the labels do not carry them.
  3. Fire Do once per wheel award.
  4. Wire Segment Index into pixi.Wheel targetIndex and fire its spinTo.
  5. Pay Prize Value from pixi.Wheel onSpinComplete.
caution

Draw the disc from Segments (normalised) so the wheel and the maths agree on the segment count. pixi.Wheel wraps an index it cannot show and warns in the console; fix the segment list, not the index.