game
A global table that contains functions for retrieving server state and client environment data, as well as managing client resources such as audio instances, Signals, and Tweens.
Methods26
function game.DestroyClientUIControl(control: ClientControlType)
Destroys the specified Client Control instance.
controlClientControlTypeThe Client Control to destroy.
function game.FindClientUIRoot(name: string) -> control ClientUIContainerControl | nil
Gets a root-level ContainerControl by name.
- If multiple root-level ContainerControls with the same name exist, the first matching ContainerControl by runtime instantiation order will be returned.
- Root-level ContainerControls are instantiated in descending order from the list displayed in the editor's Interface Layout menu.
- When a root-level ContainerControl is added to the Client UI hierarchy using the "Activate UI Control Group in Control Group Library" node on a Server Control Template containing a Client Container Control component, the created ContainerControl is appended to the Client UI hierarchy, regardless of the layer specified in its template.
- Returns nil if no matches are found.
See:
namestringThe name of the Client Control to find.
controlClientUIContainerControl | nilThe root-level ContainerControl with the specified name.
function game.GetClientUIControl(id: number) -> control ClientControlType | nil
idnumberThe runtime ID of the Client Control to find.
controlClientControlType | nilThe Client Control with the corresponding runtime ID.
function game.GetClientUIRoots() -> controls ClientUIContainerControl[]
Returns a sequence containing all active root-level ContainerControls.
controlsClientUIContainerControl[]The sequence of active root-level ContainerControls in the hierarchy.
function game.GetControllerFocus() -> ClientControlType | nil
Returns the Client Control currently focused by the controller.
- Returns nil if no Client Control is focused.
- ClientControlType | nil
The Client Control currently focused by the controller.
function game.GetControllerLeftStickAxis() -> (horizontalInput number, verticalInput number)
Returns the left stick input values of the connected controller.
- Each axis returns a range within -1 (down/left) and 1 (up/right), with 0 representing no input.
horizontalInputnumberThe horizontal axis input strength.
verticalInputnumberThe vertical axis input strength.
function game.GetControllerRightStickAxis() -> (horizontalInput number, verticalInput number)
Returns the right stick input values of the connected controller.
- Each axis returns a range within -1 (down/left) and 1 (up/right), with 0 representing no input.
horizontalInputnumberThe horizontal axis input strength.
verticalInputnumberThe vertical axis input strength.
function game.GetCursorUIPos() -> (x number, y number)
Returns the cursor position originating from the bottom-left corner of the canvas.
xnumberThe cursor x position.
ynumberThe cursor y position.
function game.GetDevice() -> device EnumItem.Device
deviceEnumItem.DeviceThe current device type.
function game.GetGlobalCustomVariableValue(entity: EnumItem.CustomVariableEntityType, varName: string) -> value any
Gets a variable set in the Custom Variable component of the specified entity.
- Returns nil if a variable with the specified name is not set in the Custom Variable component on the entity.
See:
- Enum.CustomVariableEntityType for all entities that Custom Variables can be retrieved from.
- ServerDataType for all data types that can be returned.
entityEnumItem.CustomVariableEntityTypeThe entity to get the Custom Variable from.
varNamestringThe name of the Custom Variable to get.
valueanyThe value of the Custom Variable.
function game.GetLanguageType() -> language EnumItem.LanguageType
languageEnumItem.LanguageTypeThe current language.
function game.GetStageMode() -> EnumItem.StageMode
- EnumItem.StageMode
The stage mode.
function game.GetText(textMappingId: string) -> localizedText string
Returns the localized value of a Script Text Variable by Text Mapping ID.
- If a translation is not provided for the current language, text from the Source Language will be returned.
- Returns the textMappingId if no Script Text Variable with the specified ID is found.
textMappingIdstringThe ID of the Script Text Variable.
localizedTextstringThe localized text.
function game.GetUICanvasSize() -> (width number, height number)
Returns the width and height of the canvas.
- The canvas size is typically the viewport width and height, except for controller layouts, which deduct safe area padding.
widthnumberThe width of the canvas.
heightnumberThe height of the canvas.
function game.InstantiateClientUIControl(templateIndex: number, parent: ClientControlType) -> control ClientControlType
Creates a new Client Control instance.
- The created Client Control is appended to the parent's list of children, assigning it the next largest sibling index.
See:
- ClientUIBaseControl.GetSiblingIndex for detailed sibling-index behavior.
templateIndexnumberThe index of the Client Control Template to create.
parentClientControlTypeThe Client Control which will be the parent of the created Client Control.
controlClientControlTypeThe created Client Control instance.
function game.IsAudioAlive(audioInstanceId: number) -> alive boolean
Checks if the specified audio instance is currently active in memory.
- Returns false if an audio instance for the provided ID does not exist.
audioInstanceIdnumberThe ID of the audio instance to check the status of.
alivebooleanWhether the audio instance for the given ID is alive.
function game.IsLevelTimePaused() -> paused boolean
Returns whether level time is paused.
pausedbooleanWhether level time is paused.
function game.IsTestPlay() -> testPlay boolean
Checks if the client is currently running the stage in a test play.
testPlaybooleanWhether the stage is being run as a test play.
function game.PauseLevelTime(pause: boolean)
Suspends or resumes level time.
- While paused, OnLevelUpdate lifecycle functions will not execute.
Only takes effect in single-player stages.
pausebooleanWhether to pause level time.
function game.PlayAudio2D(id: number) -> audioInstanceId number
Creates a new audio instance playing the specified audio.
idnumberThe ID of the audio clip to play.
audioInstanceIdnumberThe ID of the created audio instance.
function game.PrintClientUITree()
Prints all Client Controls in the hierarchy to the log.
function game.ServerSignal(signalName: string) -> signal ServerSignal
Creates a Server Signal instance for the specified signal name.
signalNamestringThe name of the signal.
signalServerSignalThe Server Signal instance.
function game.SetControllerFocus(control: ClientControlType)
Sets the controller focus to the specified control.
controlClientControlTypeThe Client Control to focus.
function game.StopAudio(audioInstanceId: number)
Stops the specified audio instance.
audioInstanceIdnumberThe ID of the audio instance to stop.
function game.Tween(control: ClientControlType, targetValues: TweenTarget, duration: number) -> tween Tween
Creates a Tween instance targeting the given object.
- Once created, the target values can no longer be changed.
controlClientControlTypeThe Client Control to modify the fields of.
targetValuesTweenTargetA table containing the target values of fields to modify during the Tween. A warning will be raised if a field in the table is not tweenable.
durationnumberThe duration of the Tween in seconds.
tweenTweenThe created Tween instance.
function game.TweenSequence() -> tweenSequence TweenSequence
Creates a new Tween Sequence.
tweenSequenceTweenSequenceThe created Tween Sequence.