API ReferenceGE Extensionscore
Lap Times
Lap and segment timing system for races. Tracks current time, lap/segment splits, best times, and diffs. Streams formatted timing data to the UI via `guihooks.queueStream`.
Lap and segment timing system for races. Tracks current time, lap/segment splits, best times, and diffs. Streams formatted timing data to the UI via guihooks.queueStream.
Public Functions
| Function | Signature | Description |
|---|---|---|
M.initialize | () | Resets all timing state to defaults |
M.formatTime | (seconds, addSign) → string | Formats seconds as MM:SS.mmm (optional ± sign) |
M.getDiffFlavor | (val) → string | Returns "better", "worse", or "same" for a time diff |
M.setConfiguration | (config) | Sets totalLaps, totalSegments, closedCircuit |
M.onRaceStart | (meta) | Initializes timing from race metadata |
M.onRaceStop | () | Sets status to stopped, flags all streams |
M.updateFastFromRace | (race, playerId) | Updates fast-changing data (current time, lap/segment durations) |
M.updateSlowFromRace | (race, playerId) | Updates slow-changing data (historical times, bests, diffs) |
M.updateStaticFromRace | (race, playerId) | Updates static metadata (lap count, segment count) |
M.updatePlacementFromRace | (race, playerId) | Updates placement/position data |
M.onUpdate | (dtReal, dtSim, dtRaw) | Sends flagged stream data to UI |
M.newRaceStart | (race) | Hook for new race system - configures from race object |
M.newRaceStop | () | Hook for new race system - stops timing |
UI Streams
| Stream Key | Update Rate | Content |
|---|---|---|
lapTimes_fast | Per frame (when flagged) | Current time, lap time, segment time, formatted strings |
lapTimes_slow | On segment/lap completion | Historical laps, segments, best times, diffs |
lapTimes_static | On race start/config change | Total laps, segments, circuit type |
lapTimes_placement | On position change | Vehicle placements and order |
Usage Example
-- Initialize and configure
core_lapTimes.initialize()
core_lapTimes.setConfiguration({
totalLaps = 3,
totalSegments = 8,
closedCircuit = true
})
-- Format a time value
local formatted = core_lapTimes.formatTime(93.456)
-- Result: "01:33.456"
-- Format with sign (for diffs)
local diff = core_lapTimes.formatTime(-1.234, true)
-- Result: "-00:01.234"
-- Get flavor for UI coloring
local flavor = core_lapTimes.getDiffFlavor(-0.5)
-- Result: "better"Data Flow
- Race system calls
updateFastFromRaceevery frame andupdateSlowFromRaceon segment/lap events - These functions populate stream data tables and set dirty flags
onUpdatechecks flags and sends streams viaguihooks.queueStream- UI subscribes to stream keys for real-time display
Notes
- The
combinedTimesfield in slow stream data interleaves segments and laps chronologically. - Best times are tracked per-segment-index across all laps.
- Legacy hooks (
onRaceWaypointReached,onRaceResult) exist but are no-ops. - Status values:
"stopped","started","paused","complete".
See Also
- globals -
guihooks.queueStreamfor UI streaming
Job System
Coroutine-based job system for running background tasks without blocking the game. Jobs yield control back to the engine periodically, allowing frame rendering to continue during long operations.
Levels
Level discovery, metadata, and loading system. Scans `/levels/` for available maps, enriches data with previews/spawn points/mod info, and provides the API for starting levels.