Engine

⚙️ Overview

A callback is a script function that executes repeatedly on a background thread created by the engine. Each callback receives a unique callback ID (integer) and runs at a defined interval in milliseconds.


🧩 Registration Functions

Register Callback

int register_callback(const __Internal_CallbackFn@ fn, int every_ms, int data_index)

Registers a new recurring callback function. The engine launches a lightweight thread that periodically invokes your callback, passing both its unique ID and the data_index you supplied.

Parameter

Type

Description

fn

__Internal_CallbackFn@

Function pointer to the callback (takes two integer arguments — the callback ID and the data index).

every_ms

int

Delay in milliseconds between callback executions.

data_index

int

User-defined integer value forwarded to your callback each time it runs. This can represent a dataset slot, UI layer, or logic group.

Returns: A unique callback ID (int) if successful, or 0 on failure. Drawing And Input is unique for each thread.

🧠 The callback executes in its own thread. Each iteration:

  1. Begins input collection

  2. Executes your callback function

  3. Submits the current draw list

  4. Ends input and sleeps for every_ms


Unregister Callback

Stops a previously registered callback and terminates its thread.

Parameter
Type
Description

id

int

The callback ID returned by register_callback.


🧠 Callback Function Type

The callback function type is defined internally by the engine:

Your script callback must accept two integer parameters:

Parameter

Type

Description

callback_id

int

The callback ID returned by register_callback. This uniquely identifies the running callback instance.

data_index

int

A user-defined or engine-supplied index value associated with this callback execution. Can be used to differentiate multiple data contexts handled by the same callback.


Example


🪵 Logging Helper

Example:


get_username(): string

Returns the current PCX username as a string.

Syntax


📜 Example: Animated Cursor

Last updated