System¶
Reference¶
- system.getTime()¶
Returns the amount of milliseconds passed since start of playback
- 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.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
- Returns:
Player delta time in milliseconds
- Return type:
number
- system.getDeltaGameTime()¶
Returns the current game delta time between frames in milliseconds
- Returns:
Game 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.interpolate(startValue, endValue, duration, callback, doneCallback)¶
Interpolates between startValue and endValue for duration seconds and will call the callback function
- Parameters:
startValue (
number
) – the start value to interpolate fromendValue (
number
) – the end value to interpolate toduration (
number
) – the amount of seconds to take to interpolatecallback (
function
) – the function to call. the only parameter this gets is the interpolated valuedoneCallback (
function
) – the function to call when interpolation is done. this param is optional
- system.getUserAgentString()¶
Returns the full user agent string of the browser.
- Returns:
The full user agent string.
- Return type:
str
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”
- Returns:
The name of the browser.
- Return type:
str
Usage:
1 2
local browser = System.getUserAgentName() print("Browser Name:", browser)
- system.isMobileDevice()¶
Determines if the current device is a mobile device.
- Returns:
true if the device is a mobile phone or tablet, otherwise false.
- Return type:
boolean
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.
- Returns:
true if the device supports touch input, otherwise false.
- Return type:
boolean
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)
- Returns:
“Mobile” or “Desktop”, based on device detection.
- Return type:
str
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