Scenarios Loader
M.dependencies = {'core_levels'}
Dependencies
M.dependencies = {'core_levels'}Discovers, processes, and launches scenarios. Scans level directories for scenario JSON files, resolves prefabs/previews/extensions, applies defaults, and handles both legacy scenarios and flowgraph-based scenarios.
Internal State
| Field | Type | Description |
|---|---|---|
M.processedScenarioCache | table | Cache of processed scenario data, keyed by scenario path |
Public API (Exports)
| Function | Signature | Description |
|---|---|---|
M.getList | (subdirectory?, includeAll?, skipMissions?) | Returns list of all available scenarios |
M.start | (sc) | Launches a processed scenario (or flowgraph) |
M.startByPath | (path) | Loads and starts a scenario from a file path |
M.load | (name) | Finds and starts a scenario by name |
M.loadScenario | (scenarioPath, key?) | Loads and processes a single scenario JSON |
M.processScenarioData | (scenarioKey, scenarioData, scenarioFilename) | Processes raw scenario data, applies defaults |
M.getScenarioDataForMission | (m) | Converts a gameplay mission into scenario format |
M.getLevels | (subdirectory) | Gets levels with scenarios in a subdirectory (bus routes) |
M.onFileChanged | (filename, type) | Hot-reloads scenario if source file changed |
Scenario Modules (Auto-Loaded)
M.scenarioModules = {
'scenario_scenarios', 'scenario_waypoints',
'statistics_statistics', 'scenario_raceUI', 'scenario_raceGoals'
}How It Works
Discovery (getList)
- Scans all level paths under
<level>/scenarios/for.jsonfiles - Also scans
flowgraphEditor/scenarios/for flowgraph scenarios - Scans
.flow.jsonfiles withisScenario = trueflag - Optionally includes gameplay missions with
isAvailableAsScenario - Filters
restrictToCampaignin shipping builds
Processing (processScenarioData)
- Paths: Resolves
sourceFile,directory,levelName,mission,scenarioName - Vehicles: Defaults to
{scenario_player0 = {playerUsable=true, startFocus=true}, ['*'] = {}} - Prefabs: Auto-discovers matching
.prefaband.prefab.jsonfiles via cached directory scan - Previews: Auto-discovers matching
.jpgfiles in scenario directory - Extensions: Auto-adds
{name=scenarioName, optional=true}for co-located extension files - LapConfig: Processes
BranchLapConfiginto flatlapConfig(strings only) - Attempts: Initializes retry system fields if
attemptsInfois present - Input Filters: Sets up black/white list action filters
- Mod Info: Detects mod source via
core_modmanager.getModFromPath
Launch (start)
- Stops any active campaign
- If level is already loaded, defers start until unloaded
- For flowgraph scenarios: loads flowgraph manager and sets variables
- For legacy scenarios: loads scenario modules and calls
executeScenario
Prefab Cache
M.prefabCache = {} -- levelPath → {directory → {prefabName → prefabPath}}Built once per level, caches all .prefab and .prefab.json files for fast lookup during scenario processing.
Usage Example
-- Get all available scenarios
local scenarios = scenario_scenariosLoader.getList()
-- Start a specific scenario
scenario_scenariosLoader.startByPath("/levels/gridmap/scenarios/drag_race.json")
-- Load and inspect scenario data
local sc = scenario_scenariosLoader.loadScenario("/levels/west_coast_usa/scenarios/hill_climb.json")
print(sc.name, sc.levelName, #sc.prefabs)Key Notes
- Supports three scenario types: JSON, flowgraph (
.flow.json), and mission-as-scenario processScenarioDatais idempotent - applies all defaults regardless of input completeness- The
restrictScenariossetting controls whether input filters are enforced onFileChangedenables live reload during development- Bus route scenarios use a specialized
getLevelspath with.buslines.jsonfiles - Date field is forced to string to prevent JSON encoding data loss
Additional Exports
M.triggerDelayedStart- (undocumented)
See Also
- Scenario Bus Driver - Bus Route Scenario Logic - Related reference
- Scenario Damage Goal - Damage-Based Win/Fail Condition - Related reference
- Scenario Demolition Derby - Last Vehicle Moving Wins - Related reference
- Scenario System Guide - Guide
Scenario Engine
The main scenario engine. Manages the entire scenario lifecycle: loading, state transitions, countdown, racing, finishing, multiseat, vehicle processing, waypoint processing, and UI coordination. This
Speed Goal
A scenario goal that monitors vehicle speed and triggers win or fail if the vehicle stays outside a speed range for too long. Supports min/max speed, timeout countdown, waypoint-specific checks, and d