Timer Module
Flowgraph module providing a managed timer system with pause/resume, multiple time modes (real/sim/raw), and variable-backed storage. Timers are identified by auto-incrementing IDs and support elapsed
Flowgraph module providing a managed timer system with pause/resume, multiple time modes (real/sim/raw), and variable-backed storage. Timers are identified by auto-incrementing IDs and support elapsed time queries and completion checks.
Module Properties
| Property | Value | Description |
|---|---|---|
moduleOrder | 0 | Early initialization order |
Class Methods
Lifecycle
| Method | Description |
|---|---|
C:init() | Creates a variableStorage instance and calls clear() |
C:clear() | Resets variables, timers table, global time counters, ID counter |
C:executionStopped() | Calls clear() to reset all timers |
Timer Management
| Method | Description |
|---|---|
C:addTimer(data) | Creates a new timer with mode, duration, optional start time; returns timer ID |
C:getTimer(id) | Returns the full timer object for a given ID |
C:set(id, field, val) | Sets a timer field via the variable storage system |
C:setPause(id, val) | Flags a timer for pause/unpause (applied in afterTrigger) |
C:setElapsedTime(id, time) | Overrides elapsed time-adjusts start or stores directly if paused |
C:setMode(id, mode) | Changes timer time mode (dtSim, dtReal, dtRaw); preserves elapsed time |
C:getElapsedTime(id) | Returns elapsed seconds (paused: stored value; running: global - start) |
C:isComplete(id) | Returns true when elapsed time ≥ duration |
Time Tracking
| Method | Description |
|---|---|
C:getGlobalTime(mode) | Returns accumulated global time for the given mode |
C:onUpdate(dtReal, dtSim, dtRaw) | Accumulates delta times into globalTime.real/sim/raw |
C:afterTrigger() | Finalizes pause flags: converts to elapsed time or adjusts start; finalizes variable changes |
ID Generation
| Method | Description |
|---|---|
C:getFreeId() | Returns next auto-incrementing timer ID |
Usage Example
local timerMod = mgr.modules.timer
-- Create a 10-second sim-time timer
local timerId = timerMod:addTimer({
mode = "dtSim",
duration = 10,
time = 0 -- optional: start with elapsed time offset
})
-- Check timer state
local elapsed = timerMod:getElapsedTime(timerId)
if timerMod:isComplete(timerId) then
-- Timer finished
end
-- Pause and resume
timerMod:setPause(timerId, true) -- pause
timerMod:setPause(timerId, false) -- resume
-- Switch time mode (preserves elapsed)
timerMod:setMode(timerId, "dtReal")Internal Details
- Timer data backed by
flowgraph/variableStoragefor merge-strategy-safe state - Variables stored as
{id}start,{id}mode,{id}duration - Pause uses a
pauseFlagdeferred toafterTrigger()to avoid mid-frame inconsistencies - When pausing, elapsed time is snapshot; when resuming, start time is recalculated from current global time
- Global time modes:
dtSim(simulation),dtReal(real/wall),dtRaw(unscaled)
Additional Exports
-
idCounter-number- (see source) -
idCounter-number- (see source)
See Also
- Flowgraph Action Module - Related reference
- Flowgraph AI Recording Module - Related reference
- Flowgraph Button Module - Related reference
- FlowGraph Guide - Guide
Thread Module
Flowgraph module for inter-flowgraph messaging and child project management. Enables flowgraph managers to send/receive messages and spawn child flowgraph projects that communicate back via the thread
Traffic Module
Flowgraph module wrapping `gameplay_traffic` and `gameplay_parking` APIs for flowgraph-managed traffic and parked car activation/deactivation. Automatically cleans up traffic and parking state when th