System

Reference

system.getTime()

Returns the current player time in milliseconds

Returns:

Player time in milliseconds

Return type:

number

system.getDeltaTime()

Returns the current player delta time between frames in milliseconds

Returns:

Player delta time in milliseconds

Return type:

number

system.sleep(ms)

Waits for a given time in milliseconds

Parameters:

ms (number) – time in milliseconds

Returns:

Returns a promise that will fulfill after the time has passed

Return type:

Promise

system.markPromiseAsBlocking(promise)

A promise will be marked as blocking, meaning the execution of the current lifecycle function will not return unless this


Promise is fulfilled and the render pipeline will be blocked until then

Parameters:

promise (Promise) – the promise to wait for

Examples

Retrieve playtime
local System = require 'engine/system'
local Console = require 'engine/console'

local time = System.getTime()
Console.log(time)
Sleep for a while
local System = require 'engine/system'
local Console = require 'engine/console'

Console.log("Going to sleep for a second...")
System.sleep(1000):next(function()
    Console.log("Hello again!")
end)
Block lifecycle hook until promise is resolved
local System = require 'engine/system'
local Console = require 'engine/console'

function init()
    Console.log("Going to sleep for a second...")

    -- Mark this promise as blocking, so init() is not returned from unless this promise is also fulfilled.
    -- This can be either done through System.markPromiseAsBlocking() or on the promise itself with :markAsBlocking()
    System.sleep(1000):next(function()
        Console.log("Hello again!")
    end):markAsBlocking()
end

function render()
    -- This will not execute until the sleep promise has fulfilled
end