@l8b/time
v1.0.11
Published
**LootiScript API Binding** - System information and timing utilities.
Readme
@l8b/time
LootiScript API Binding - System information and timing utilities.
Note: This package is used as an API binding for LootiScript in the l8b engine.
API Reference
system
Global object providing system information and utilities.
System Properties
system.time
Get current time in milliseconds since epoch.
local currentTime = system.time
// Returns: 1701234567890system.fps
Get current frames per second.
local fps = system.fps
// Returns: 60system.cpu_load
Get CPU load (0.0 to 1.0).
local load = system.cpu_load
// Returns: 0.45system.update_rate
Get update rate (updates per second).
local rate = system.update_rate
// Returns: 60system.language
Get browser/system language.
local lang = system.language
// Returns: "en-US"system.loading
Get loading progress (0 to 100).
local progress = system.loading
// Returns: 100 (when fully loaded)
// Check if still loading
if system.loading < 100 then
// Show loading screen
endInput Availability
system.inputs.keyboard
Check if keyboard is available.
if system.inputs.keyboard == 1 then
// Keyboard is available
endsystem.inputs.mouse
Check if mouse is available.
if system.inputs.mouse == 1 then
// Mouse is available
endsystem.inputs.touch
Check if touch is available.
if system.inputs.touch == 1 then
// Touch screen is available
// Show touch controls
endsystem.inputs.gamepad
Check if gamepad is available.
if system.inputs.gamepad == 1 then
// Gamepad API is available
// Show gamepad controls
endSystem Functions
system.pause()
Pause the game execution.
system.pause()system.exit()
Exit the game (close window).
system.exit()system.prompt()
Show a prompt dialog and get user input.
system.prompt("Enter your name:", function(result)
Console.log("Hello " .. result)
playerName = result
end)Parameters:
text(string) - Prompt messagecallback(function) - Called with user input
system.say()
Show an alert dialog.
system.say("Game Over!")
system.say("You won! Score: " .. score)Parameters:
text(string) - Alert message
File Drop Support
system.file.dropped
Check if a file was dropped (drag and drop).
if system.file.dropped == 1 then
// File was dropped
// Handle file
endJavaScript Interop
system.javascript
Object for JavaScript interoperability.
// Access JavaScript functions
system.javascript.myFunction()
// Access JavaScript objects
local value = system.javascript.myObject.propertyThread Management
system.threads
Array of active threads.
local threadCount = #system.threads
Console.log("Active threads: " .. threadCount)Additional Flags
system.disable_autofullscreen
Disable automatic fullscreen.
system.disable_autofullscreen = 1 // Disable
system.disable_autofullscreen = 0 // Enablesystem.preemptive
Enable preemptive threading.
system.preemptive = 1 // Enable
system.preemptive = 0 // DisableExample Usage
Loading Screen
function draw()
if system.loading < 100 then
// Show loading screen
screen.clear("#000")
screen.setColor("#FFF")
screen.drawText("Loading...", 10, 10, 16)
// Draw progress bar
local progress = system.loading / 100
screen.fillRect(10, 30, progress * 200, 10, "#0F0")
screen.drawRect(10, 30, 200, 10, "#FFF")
else
// Game is loaded, draw game
drawGame()
end
endFPS Counter
function draw()
screen.clear("#000")
// Draw FPS
screen.setColor("#FFFF00")
screen.drawText("FPS: " .. system.fps, 10, 10, 12)
// Draw game
drawGame()
endInput Detection
function init()
// Detect available inputs
if system.inputs.touch == 1 then
Console.log("Touch controls available")
showTouchControls = true
end
if system.inputs.gamepad == 1 then
Console.log("Gamepad available")
showGamepadHints = true
end
endUser Input
function showNamePrompt()
system.prompt("Enter your name:", function(name)
if name ~= "" then
playerName = name
system.say("Welcome, " .. name .. "!")
startGame()
end
end)
endPause Menu
local paused = false
function update()
if keyboard.press.ESCAPE == 1 then
if paused then
// Resume
paused = false
else
// Pause
paused = true
system.pause()
end
end
if not paused then
// Update game logic
updateGame()
end
endPlatform Detection
function init()
// Check platform capabilities
local isMobile = system.inputs.touch == 1
local hasGamepad = system.inputs.gamepad == 1
if isMobile then
// Setup mobile controls
setupTouchControls()
else
// Setup desktop controls
setupKeyboardControls()
end
if hasGamepad then
// Enable gamepad support
enableGamepad()
end
// Log system info
Console.log("Language: " .. system.language)
Console.log("Update rate: " .. system.update_rate)
endTime-Based Events
local startTime = 0
local eventTriggered = false
function init()
startTime = system.time
end
function update()
local elapsed = system.time - startTime
// Trigger event after 5 seconds (5000ms)
if elapsed > 5000 and not eventTriggered then
system.say("5 seconds have passed!")
eventTriggered = true
end
end