The value wraps around at 2^32 ms (approximately 49.7 days). To measure elapsed time correctly across wrap-around, always use time.since() rather than subtracting timestamps manually.
Lua code:
local start = time.now()
Parameter: "timestamp" (integer): A value previously returned by time.now().
Returns: elapsed milliseconds (integer).
Uses unsigned 32-bit subtraction internally, so it handles wrap-around correctly as long as the interval is under ~24.8 days.
Lua code:
local start = time.now()
-- ... do work ...
local elapsed = time.since(start)
print("Took " .. elapsed .. " ms")
This is the preferred way to control loop timing and is equivalent to a yield-based busy wait.
Parameter: "ms" (integer): Duration in milliseconds
Lua code:
-- Run at approximately 20 Hz
while true do
-- do work
time.delay(50)
end
The script resumes as soon as the scheduler returns to it.
Use yield() in tight loops where you want maximum speed but still need to share CPU time. Use time.delay() when you want to control how often the loop runs.
Lua code:
while true do
-- process all pending CAN frames as fast as possible
while can.count() > 0 do
local frame = can.recv()
-- handle frame
end
yield()
end
For more information about the MaxxECU user scripts, see User Scripts (LUA), or directly reference the LUA api reference and LUA examples. For more all available LUA settings and options, see Script Code, Script Input Control, Output Functions and Script RT values.