Events are the primary communication channel between the simulation engine and the frontend. Every event is a plain dict appended toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/StakeEngine/math-sdk/llms.txt
Use this file to discover all available pages before exploring further.
gamestate.book.events. When the RGS selects a simulation from the library, it returns the full events array in the play/ API response, and the frontend SDK processes each event in order to drive animations and UI updates.
Event structure
Every event follows this base structure:index is the zero-based position of the event in the book’s event list. type is a string constant defined in EventConstants.
Emitting events
Call event functions after the state change they describe. Passgamestate (i.e. self inside GameState):
gamestate.book.add_event(event) internally, which performs a deep copy before appending. You do not need to copy the event dict yourself.
Importing event functions
Executables methods (e.g. evaluate_finalwin() calls final_win_event()). You only need to import them directly for custom event sequences.
Standard event types
reveal
Emitted once per board draw. Describes the full board state including padding symbols.board— 2D array indexed[reel][row]. Each symbol is{"name": "..."}plus any active special attributes (e.g.{"name": "M", "multiplier": 3}).paddingPositions— the reel-stop index selected for each reel. Used by the frontend to animate the spin.gameType— current value ofgamestate.gametype.anticipation— per-reel anticipation flag array. Non-zero values trigger anticipation animations on that reel.
config.include_padding = True (the default), the board array includes one extra row at the top and bottom of each reel column for the padding symbols.
Emitted by: reveal_event(gamestate) — called automatically by draw_board(emit_event=True).
winInfo
Describes all winning combinations from the current board evaluation.totalWin— sum of all wins in this event, in cents (integer, multiplied by 100).wins— array of individual win objects.symbol— winning symbol name.kind— number of matching symbols.win— payout for this win in cents.positions— board positions of the winning symbols. Row indices are offset by+1wheninclude_padding = True.meta— optional additional data (e.g.winWithoutMultfor multiplier games).
win_info_event(gamestate).
setWin
Updates the cumulative win ticker for a single outcome.amount— current spin win in cents (clamped to wincap × 100).winLevel— integer level (1–10) fromconfig.get_win_level(), used by the frontend to select the correct win animation tier.
set_win_event(gamestate, winlevel_key="standard").
setTotalWin
Updates the total win display for the entire betting round, accumulating wins across all free spins.amount— cumulativerunning_bet_winin cents (clamped to wincap × 100).
set_total_event(gamestate).
finalWin
Emitted once per simulation, after all spin and free spin actions complete. Carries the final payout multiplier.amount— final payout in cents (clamped to wincap × 100). Matchesbook.payoutMultiplier.
10.
Emitted by: final_win_event(gamestate) — called automatically by evaluate_finalwin().
updateFreeSpin
Emitted at the start of each free spin before the board draw.amount— current free spin number (1-based after the firstfs += 1call).total— total free spins awarded this round (including retriggers).
update_freespin_event(gamestate) — called automatically by update_freespin().
freeSpinTrigger / freeSpinRetrigger
Emitted when free spins are awarded. UsesfreeSpinTrigger when triggered from the base game, freeSpinRetrigger on a retrigger.
totalFs— total free spins now available.positions— board positions of the scatter symbols that triggered free spins.
fs_trigger_event(gamestate, basegame_trigger=True/False, freegame_trigger=True/False).
freeSpinEnd
Emitted once when the free spin loop ends.amount— total free game winnings in cents.winLevel— win level fromget_win_level()using theendFeaturescale (levels 1–10 with higher thresholds).
freespin_end_event(gamestate) — called automatically by end_freespin().
tumbleBoard
Emitted during tumble/cascade games to describe which symbols are removed and what replaces them.explodingSymbols— positions of symbols removed from the board (offset by +1 if padding is active).newSymbols— per-reel arrays of new symbols that fall into the vacated positions.
tumble_board_event(gamestate) — called automatically by tumble_game_board().
setTumbleWin / updateTumbleWin
Used for running tumble win banners:setTumbleWin— sets the cumulative tumble win banner to the current spin win total.updateTumbleWin— updates the running tumble win for the current cascade step.
set_tumble_event(gamestate) and update_tumble_win_event(gamestate).
updateGlobalMult
Emitted when the global multiplier increments.globalMult— current integer multiplier value after incrementing.
update_global_mult_event(gamestate) — called automatically by update_global_mult().
enterBonus
Emitted to explicitly indicate entry into a feature game (e.g. a buy-bonus mode). Used when the bonus entry reason needs to be communicated to the frontend separately from a scatter trigger.reason— string describing why the bonus was entered (e.g."buyBonus","scatter"). Read fromgamestate.bonus_type.
enter_bonus_event(gamestate).
wincap
Emitted when the running win reachesconfig.wincap. Signals the frontend to stop displaying further win events.
amount— the wincap amount in cents.
wincap_event(gamestate) — called automatically by evaluate_wincap().
book.add_event()
All event functions call this method internally. You can also call it directly to emit a custom event:Book class (src/state/books.py) stores events as a list and performs a deep copy on each append to prevent mutation of past events.
Event ordering
Emit events in the order they occur during the spin. The frontend processes events sequentially — out-of-order events will produce incorrect animations. The standard sequence for a base game spin with wins is:reveal— board drawwinInfo— winning combinationssetWin— cumulative spin win tickersetTotalWin— cumulative round win tickerfreeSpinTrigger(if applicable)- (free spin events…)
finalWin— end of round
How events reach the frontend
The simulation library stores every book as a JSON object. When a player spins:- The RGS selects a simulation ID from the lookup table (weighted by the optimization output).
- It retrieves the corresponding book from
library/books/books_<mode>.jsonl. - It returns the book’s
eventsarray in theplay/API response. - The frontend SDK consumes the events in order.
