Sgwave Med
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGwave_med is a stategraph (state machine) that controls the lifecycle of a medium-sized wave entity in the ocean environment. It defines three sequential states—rise, idle, and lower—which handle animation playback, sound effects, collision activation, and eventual entity removal. This stategraph is used for visual ocean wave effects, likely spawned procedurally or in response to environmental triggers.
It relies on the commonstates.lua module via require, though no direct function calls from that module are used in the source code.
Usage example
-- Typically instantiated and driven by a corresponding prefab (e.g., `rogue_wave_med`)
local inst = SpawnPrefab("rogue_wave_med")
-- Stategraph is automatically attached; no manual stategraph manipulation needed
-- The wave entity sets properties like idle_time and soundrise before spawning the stategraph
Dependencies & tags
Components used: None explicitly. Assumes access to the following entity APIs: AnimState, SoundEmitter, and sg.
Tags: Adds rising in the rise state, idle in the idle state, and lowering in the lower state. These tags are added/removed automatically by the stategraph system.
Properties
No public properties are defined in this stategraph. The state transitions depend on runtime instance properties such as:
inst.idle_time(number, optional, defaults to5seconds in stateidle)inst.soundrise(string, optional, sound name for rising animation)inst.soundloop(string, optional, sound name for looping during idle)inst.waitingtolower(boolean, used internally to control transition fromidle→lower)
These are expected to be set on the owning entity instance before or during stategraph initialization.
Main functions
This stategraph file does not expose standalone functions; it returns a preconfigured StateGraph object with the name "wave" and the defined state set. State behaviors are implemented via onenter, ontimeout, and EventHandler closures inside state definitions.
State Definitions (Internal)
rise state
- Description: The initial state; plays the
"appear"animation and triggers sound effects. After animation completes, transitions toidle. - Tags:
"rising" - Key behaviors:
- On enter: plays
"appear"animation. - Time event after
5*FRAMES: playssoundrise(if set) and startssoundloop(if set). - On
animover: transitions toidle.
- On enter: plays
idle state
- Description: Keeps the wave visible; activates collision and waits for a timeout before beginning to lower.
- Tags:
"idle" - Key behaviors:
- On enter: activates collision (
inst:activate_collision()), plays"idle"animation (non-looping), and sets a timeout (inst.idle_timeor5seconds). - On
animover: ifinst.waitingToLoweris true, transitions tolower; otherwise re-plays"idle"animation. - On timeout: sets
inst.waitingtolower = true(enabling transition on nextanimover).
- On enter: activates collision (
lower state
- Description: Ends the wave effect; plays
"disappear"animation, kills any loop sound, and removes the entity. - Tags:
"lowering" - Key behaviors:
- On enter: resumes animation playback, plays
"disappear"animation, and killssoundloopif present. - On
animover: callsinst:Remove()to destroy the entity.
- On enter: resumes animation playback, plays
Events & listeners
- Listens to:
animover: handled inrise,idle, andlowerstates to trigger state transitions or re-play animations.- Timeout event (from
SetTimeout) in theidlestate to setwaitingtolower.
- Pushes: This stategraph does not push custom events. It relies on built-in stategraph mechanics and entity removal.