Skip to content

Lua API: 0. Runtime and Engine

MCUmbrella edited this page Nov 24, 2023 · 1 revision

Runtime

Static functions

log

Print messages to the console.

Parameter:

  • Number lvl (optional): Log level. 0=info, 1=warning, 2=error. Default: 0
  • String msg: The message to be logged.

Example:

  • Runtime.log("Hello world!")
  • Runtime.log(2, "Failed to save game progress")

execute

Execute another Lua script.

Parameter:

  • String path: The path to the script, starts at "(user project folder)/data/lua/".

Example:

  • Runtime.execute("custom.lua"): Call "(user project folder)/data/lua/custom.lua"

Engine

Static functions

stop

Stop the engine.

Example:

  • Engine.stop()

getState

Get the state of the engine.

Return:

  • 0: Uninitialized
  • 1: Initializing
  • 2: Stopped
  • 3: Running
  • 4: Stopping

Example:

engineState = Engine.getState()
Runtime.log("The Engine's current state is " .. engineState)

currentTick

Get the current tick. (Said another way, how many times has the tick() function been executed)

Return: Integer starting from 0.

Example:

-- Assuming target TPS is set to 60 (default value)
if (Engine.currentTick() % 60 == 59) then
  Runtime.log("Hello world!") -- this will be executed every second
end