Skip to content

GameState

The GameState library contains methods and events related to the global game state - that is, whether it's in a session, loading, paused, etc.

Its events are helpful for initialization purposes. ClientReady, for example, fires when the client transitions from PrepareRunning to Running and is a great moment to initialize anything that could need the client character to be present and/or send messages to the server (both of which are not reliable to do before that point).

GameStateLib Class

Inherits from Feature.

Events and Hooks

GamePaused (event)

GameUnpaused (event)

StateChanged (event)

@field From GameState

@field To GameState

GameReady (event)

Fires when the game transitions from PrepareRunning to Running (on the client)

or when transitioning from Sync to Running (on the server)

Tick (event)

Fired every tick.

@field DeltaTime integer Milliseconds elapsed since last tick

RunningTick (event)

Fired every tick while the game is not paused.

@field DeltaTime integer Milliseconds elapsed since last tick (NOT the last running tick)

LuaResetted (event)

ClientReady (event)

Fired when the client transitions from PrepareRunning to Running,

as well as when lua is reset.

@field CharacterNetID NetId

@field ProfileGUID GUID

@field FromReset boolean `true` if the event was fired from a lua reset.

RegionStarted (event)

Server-only.

@field LevelID string

Methods

GetState
function GameStateLib.GetState() -- (Server-only)
   -> GameState
GetState
function GameStateLib.GetState() -- (Client-only)
   -> GameState
IsInMainMenu
function GameStateLib.IsInMainMenu()
   -> boolean

Returns whether the game is in a main menu-related state.

IsInRunningSession
function GameStateLib.IsInRunningSession()
   -> boolean

Returns whether the game state is within a running session (not paused)

IsInSession
function GameStateLib.IsInSession()
   -> boolean

Returns whether the game state is currently in a session.

IsLoading
function GameStateLib.IsLoading()
   -> boolean

Returns whether the game is within a loading-related state.

IsPaused
function GameStateLib.IsPaused() -- (Client-only)
   -> boolean
IsPaused
function GameStateLib.IsPaused() -- (Server-only)
   -> boolean
IsSessionLoaded

function GameStateLib.IsSessionLoaded() -- (Server-only)
   -> boolean