System

This module provides functions to interact with the operating system. It contains functions to get screen information, manipulate the garbage collector, and open URLs in the default browser.

Handled structures

GenericCommand

This struct represents a generic command in the command buffer. It allows to iterate over the commands in the buffer.

Fields:
  • hash : uint64 - hash of the command is used to identify the type of the command

  • size : uint - size of the command is used to determine how much data to read for the command

CommandBuffer

This class represents a buffer of commands that can be written to and read from. It is designed for interacting with input, physics events, and similar systems.

Function annotations

cheat

The [cheat] annotation marks a top-level function as a console-invokable cheat/command. Cheats are registered at startup and can be called from the in-game console. This is useful for quick debugging, spawning test data, toggles, and developer tools. Most basic dasLang types are supported as function parameters (int, float (or double), bool, string, float2, float3, etc) Any registered cheat can also be invoked from code using the exec_cheat function.

Note

If the optional name parameter is omitted, the function identifier is used as the cheat name. Use a dotted custom name (for example game.restart) to group cheats or avoid name collisions.

Example of registering cheats:

[cheat]
def restart(level : int = 1) {
    createLevel(level)
}

[cheat(name="game.reset_best_scores")]
def reset_best_scores_cheat() {
    remove_storage(STORAGE_KEY)
}

Functions

get_resolution(): int2
Returns:
  • int2 - the resolution of the screen as (x, y) coordinates

get_run_in_background(): bool
Returns:
  • bool - true if the game is configured to run in the background, false otherwise

get_target_fps(): float
Returns:
  • float - the target frame rate of the user script execution

set_run_in_background(runInBackground: bool)

Sets whether the game should continue running when in the background or should be paused. Default is false, meaning the game will be paused when not in the foreground.

Arguments:
  • runInBackground : bool

set_target_fps(value: float): float

Sets the target frame rate of the user script execution. Value are clamped to the range [0.0, 1000.0] and the new target frame rate is returned. If the value is set to 0.0, the target frame rate is unlimited.

Arguments:
  • value : float - frames per second which will be set

Returns:
  • float - the new target frame rate

Logging functions

error(text: string)

prints the provided line to console, marking it as an error

Arguments:
  • text : string implicit

print(text: string)

prints the provided line to console

Arguments:
  • text : string implicit

warning(text: string)

prints the provided line to console, marking it as a warning

Arguments:
  • text : string implicit

Mouse cursor functions

get_mouse_cursor_locked(): bool
Returns:
  • bool - true if set_mouse_cursor_locked was called with true, false otherwise

is_mouse_cursor_locked(): bool
Returns:
  • bool - true if the mouse cursor is currently locked to the window, false otherwise

set_mouse_cursor_locked(lock: bool = true)

Locks the mouse cursor to the window and automatically hides it.

The mouse cursor will be hidden while locked and will reappear when unlocked.

Arguments:
  • lock : bool - if true, the mouse cursor will be locked to the window. If false, the mouse cursor will be unlocked.

Note

The mouse cursor can only be locked if the window has focus, so the user may need to click on the window to switch focus to it and confirm the lock.

The Escape key can always be used to unlock the mouse cursor.

The is_mouse_cursor_locked function can be used to check if the mouse cursor is actually locked and can be used to implement custom logic based on the lock state (pause screen, etc).

Note

The mouse lock will be applied instantly when the system processes UI events such as UIMouseEventType.MouseDown, UIMouseEventType.MouseUp, UIMouseEventType.MouseClick, or when the user has already confirmed the lock by clicking on the window.

show_mouse_cursor(show: bool = true)

Shows or hides the mouse cursor based on the ‘show’ parameter

Arguments:
  • show : bool - Indicates whether to show (true) or hide (false) the mouse cursor

Garbage collector

gc_collect_all()

Performs garbage collection both in the global heap and in the strings heap

gc_collect_heap()

Performs garbage collection specifically in the global heap (excluding strings)

gc_collect_strings()

Performs garbage collection specifically in the strings heap

get_gc_enabled(): bool
Returns:
  • bool - whether the automatic garbage collection is currently enabled

set_gc_enabled(enabled: bool)

enables or disables the automatic garbage collection

Arguments:
  • enabled : bool - set true to enable automatic garbage collection, false to disable

Warning

Don’t disable garbage collection unless you know what you’re doing. Manual garbage collection should only be used when there are issues with the automatic garbage collection.

Cheats

exec_cheat(cheat: string; arg1: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

exec_cheat(cheat: string): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

exec_cheat(cheat: string; arg1: any; arg2: any; arg3: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

exec_cheat(cheat: string; arg1: any; arg2: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

exec_cheat(cheat: string; arg1: any; arg2: any; arg3: any; arg4: any; arg5: any; arg6: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

  • arg4 : any

  • arg5 : any

  • arg6 : any

exec_cheat(cheat: string; arg1: any; arg2: any; arg3: any; arg4: any; arg5: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

  • arg4 : any

  • arg5 : any

exec_cheat(cheat: string; arg1: any; arg2: any; arg3: any; arg4: any; arg5: any; arg6: any; arg7: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

  • arg4 : any

  • arg5 : any

  • arg6 : any

  • arg7 : any

exec_cheat(cheat: string; arg1: any; arg2: any; arg3: any; arg4: any): bool

Invoke a registered cheat by given name.

Arguments:
  • cheat : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

  • arg4 : any

exec_cheat(arg0: string; arg1: any; arg2: any; arg3: any; arg4: any; arg5: any; arg6: any; arg7: any; arg8: any): bool

Invoke a registered cheat by given name.

Arguments:
  • arg0 : string

  • arg1 : any

  • arg2 : any

  • arg3 : any

  • arg4 : any

  • arg5 : any

  • arg6 : any

  • arg7 : any

  • arg8 : any

Command buffer

get_name(cmd: GenericCommand): string

Get the name of the given command

Arguments:
Returns:
  • string - The name of the command

has_read_bytes(cb: CommandBuffer): bool
Arguments:
Returns:
  • bool - true if there are any bytes to read in the CommandBuffer, and false otherwise

total_written_bytes(cb: CommandBuffer): uint
Arguments:
Returns:
  • uint - the total number of bytes written to the command buffer