Miliastra Wonderland Lua API

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.

Parameters
controlClientControlType

The 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:

Parameters
namestring

The name of the Client Control to find.

Returns
controlClientUIContainerControl | nil

The root-level ContainerControl with the specified name.

function game.GetClientUIControl(id: number) -> control ClientControlType | nil

Gets a Client Control by runtime ID.

  • Returns nil if no matches are found.

See:

Parameters
idnumber

The runtime ID of the Client Control to find.

Returns
controlClientControlType | nil

The Client Control with the corresponding runtime ID.

function game.GetClientUIRoots() -> controls ClientUIContainerControl[]

Returns a sequence containing all active root-level ContainerControls.

Returns
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.
Returns
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.
Returns
horizontalInputnumber

The horizontal axis input strength.

verticalInputnumber

The 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.
Returns
horizontalInputnumber

The horizontal axis input strength.

verticalInputnumber

The vertical axis input strength.

function game.GetCursorUIPos() -> (x number, y number)

Returns the cursor position originating from the bottom-left corner of the canvas.

Returns
xnumber

The cursor x position.

ynumber

The cursor y position.

function game.GetDevice() -> device EnumItem.Device

Returns the current input device type.

See:

Returns
deviceEnumItem.Device

The 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:

Parameters
entityEnumItem.CustomVariableEntityType

The entity to get the Custom Variable from.

varNamestring

The name of the Custom Variable to get.

Returns
valueany

The value of the Custom Variable.

function game.GetLanguageType() -> language EnumItem.LanguageType

Returns the language used by the client.

See:

Returns
languageEnumItem.LanguageType

The current language.

function game.GetStageMode() -> EnumItem.StageMode

Returns the current stage mode.

See:

Returns
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.
Parameters
textMappingIdstring

The ID of the Script Text Variable.

Returns
localizedTextstring

The 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.
Returns
widthnumber

The width of the canvas.

heightnumber

The 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:

Parameters
templateIndexnumber

The index of the Client Control Template to create.

parentClientControlType

The Client Control which will be the parent of the created Client Control.

Returns
controlClientControlType

The 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.
Parameters
audioInstanceIdnumber

The ID of the audio instance to check the status of.

Returns
aliveboolean

Whether the audio instance for the given ID is alive.

function game.IsLevelTimePaused() -> paused boolean

Returns whether level time is paused.

Returns
pausedboolean

Whether level time is paused.

function game.IsTestPlay() -> testPlay boolean

Checks if the client is currently running the stage in a test play.

Returns
testPlayboolean

Whether 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.

Parameters
pauseboolean

Whether to pause level time.

function game.PlayAudio2D(id: number) -> audioInstanceId number

Creates a new audio instance playing the specified audio.

Parameters
idnumber

The ID of the audio clip to play.

Returns
audioInstanceIdnumber

The 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.

Parameters
signalNamestring

The name of the signal.

Returns
signalServerSignal

The Server Signal instance.

function game.SetControllerFocus(control: ClientControlType)

Sets the controller focus to the specified control.

Parameters
controlClientControlType

The Client Control to focus.

function game.StopAudio(audioInstanceId: number)

Stops the specified audio instance.

Parameters
audioInstanceIdnumber

The 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.
Parameters
controlClientControlType

The Client Control to modify the fields of.

targetValuesTweenTarget

A 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.

durationnumber

The duration of the Tween in seconds.

Returns
tweenTween

The created Tween instance.

function game.TweenSequence() -> tweenSequence TweenSequence

Creates a new Tween Sequence.

Returns
tweenSequenceTweenSequence

The created Tween Sequence.