System¶
Reference¶
- system.getTime()¶
Returns the amount of milliseconds passed since start of playback
- system.getDeltaTime()¶
Returns the current player delta time between frames in milliseconds
- system.getGameTime()¶
Returns the current game time. This will usually be identical to getTime() except if there were pauses in the game, then the game time will be a smaller number
- system.getDeltaGameTime()¶
Returns the current game delta time between frames in milliseconds
- system.sleep(ms)¶
Waits for a given time in milliseconds
- 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
- system.getUserAgentString()¶
Returns the full user agent string of the browser.
Usage:
1 2
local uaString = System.getUserAgentString() print("User Agent:", uaString)
- system.getUserAgentName()¶
Returns the name of the browser being used.
Possible return values: “Firefox” “Chrome” “Safari” “Edge” “Opera” “Internet Explorer” “Unknown”
Usage:
1 2
local browser = System.getUserAgentName() print("Browser Name:", browser)
- system.isMobileDevice()¶
Determines if the current device is a mobile device.
Usage:
1 2 3 4 5
if System.isMobileDevice() then print("Running on a mobile device") else print("Running on a desktop device") end
- system.isTouchDevice()¶
Determines if the current device supports touch input.
This is useful for games that need to handle touch events differently from mouse events.
Usage:
1 2 3
if System.isTouchDevice() then print("Touch input available") end
- system.getDeviceType()¶
Returns the type of device the user is running on.
Possible return values: “Mobile” (Phones, tablets, etc.) “Desktop” (Laptops, PCs)
Usage:
1
print("Device Type:", System.getDeviceType())
Examples¶
local System = require 'engine/system'
local Console = require 'engine/console'
local time = System.getTime()
Console.log(time)
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)
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