Electrics Module Reference
Module defined in `lua/vehicle/electrics.lua`. This module manages the vehicle's electrical systems, including lights, signals, horn, ignition states, and various sensor-derived values. It acts as the
Module defined in lua/vehicle/electrics.lua. This module manages the vehicle's electrical systems, including lights, signals, horn, ignition states, and various sensor-derived values. It acts as the central data bus for the vehicle.
See Also
- Controller: For logic that reads/writes to electrics.
- Communication: For using electrics as a data bus.
- Input: For user input sources.
State Fields
| Variable | Description |
|---|---|
disabledState | Table tracking which electrics values are currently disabled or overridden. |
values | Master storage for electrical values. Booleans are stored as 1/0. Most values are updated via Input or Powertrain. |
Standard Value Keys (electrics.values)
Exhaustive list of keys used in core BeamNG systems.
User Inputs
throttle,brake,clutch,steering,parkingbrake: Normalized smoothed inputs (0-1, steering is -1 to 1).throttle_input,brake_input,clutch_input,steering_input,parkingbrake_input: Raw user inputs.signal_left_input,signal_right_input: Raw indicator inputs.
Engine & Powertrain
rpm,idlerpm,maxrpm: Engine speeds (1/min).rpmTacho: Smoothed RPM for UI needles.rpmspin: Visual rotation factor for engine parts.engineLoad,engineRunning,running: Powertrain operational state.engineThrottle: Actual throttle applied by the engine controller.ignition,ignitionLevel: Boolean running state and level (0: Off, 1: Acc, 2: On, 3: Start).radiatorFanSpin: Visual rotation factor for the cooling fan.exhaustFlow: Current volume of exhaust gases.twoStep: Boolean indicating if 2-step launch control is active.
Forced Induction (Turbo/Supercharger)
boost,boostMax: Current and maximum boost pressure.turboBoost,turboBoostMax: Specific turbo boost pressures.turboRPM,turboRpmRatio,turboSpin: Turbocharger turbine speed and visual rotation.
Transmission & Drivetrain
gear: Human-readable gear name (e.g., "N", "1", "R").gearIndex: Numerical gear index (0: Neutral, >0: Forward, <0: Reverse).gearModeIndex: Normalized position of the gear selector.gear_A,gear_M: Automatic and Manual gear display values.gearboxMode: Current behavior mode ("arcade" or "realistic").clutchRatio,clutchRatio1,clutchRatio2: Clutch engagement ratios (0-1).driveshaft,driveshaft_F: Rotation factors for driveshafts.isShifting: Boolean flag for active gear changes.smoothShiftLogicAV: Smoothed angular velocity used for shift decision logic.
Physics & Motion
wheelspeed,airspeed,airflowspeed,virtualAirspeed: Velocities (m/s).altitude: Height above sea level (m).accXSmooth,accYSmooth,accZSmooth: Smoothed G-forces (m/s²).avgWheelAV: Averaged angular velocity of all wheels.freezeState: Boolean indicating if physics are frozen.
Safety & Stability (ESC/ABS/TCS)
hasABS,hasESC,hasTCS: Boolean hardware presence flags.absActive,escActive,tcsActive: Boolean activity flags.abs,esc,tcs: System override/mode states.isABSBrakeActive,isTCBrakeActive,isYCBrakeActive: Specific intervention flags.dseWarningPulse: Trigger for dashboard stability warning lights.
Lighting & Signals
lights,lights_state: Master light switch position (0: Off, 1: Low, 2: High).lowbeam,highbeam,fog: Active light state flags.signal_L,signal_R,hazard: Turn signal and hazard states.turnsignal: Combined signal value for UI.brakelights,parkingbrakelight: Active braking light flags.lightbar: Emergency lightbar state.highbeam_wigwag_L,highbeam_wigwag_R: Alternate flashing for emergency lights.reverse_wigwag_L,reverse_wigwag_R: Alternate flashing for reverse.
Visual Filaments & Glow
foglight_filament,highbeam_filament,lowhighbeam_filament,signal_L_filament,signal_R_filament: Smoothed glow factors for light bulbs.brakeGlow_FL...RR: Heat-based glow values for brake discs.
Energy & Fluids
fuel,fuelCapacity,fuelVolume: Fuel level (0-1), capacity (L), and current volume (L).lowfuel: Boolean warning flag.oil,oiltemp: Oil pressure warning and temperature (°C).watertemp: Engine coolant temperature (°C).lowpressure: Pneumatic system pressure warning (air brakes).
Instrumentation
odometer,trip: Cumulative and trip distance travel (m).checkengine: Boolean malfunction indicator flag.
Body & Couplers
door_FL_coupler_notAttached...RR: Detachment flags for door latches.hoodCatchCoupler_notAttached,hoodLatchCoupler_notAttached,trunkCoupler_notAttached: Latch status.
Thermals (Nested)
wheelThermals: Table containingFL,FR,RL,RRcomponents:brakeCoreTemperature,brakeSurfaceTemperature,brakeThermalEfficiency.
Public API
| Function | Signature | Description |
|---|---|---|
electrics.horn | (state) | Controls horn sound and logic. |
electrics.setIgnitionLevel | (level) | Directly sets the vehicle's ignition state. |
electrics.setAllowedIgnitionLevels | (levels) | Restricts valid ignition states for the vehicle. |
electrics.toggleIgnitionLevelOnDown | () / toggleIgnitionLevelOnUp() | Handlers for stepped ignition input (cycling through levels). |
electrics.setLightsState | (state) | Manually sets master light switch index. |
electrics.toggle_lights | () | Cycles through master light states (Off -> Low -> High -> Off). |
electrics.set_left_signal | (state, autoCancel) / set_right_signal(...) | Controls turn signal states. |
electrics.stop_turn_signal | () | Cancels any active left or right turn signals. |
electrics.set_warn_signal | (value) | Enables or disables hazard warning lights. |
electrics.set_lightbar_signal | (state) | Controls emergency signals. |
electrics.set_fog_lights | (state) | Controls fog light status. |
electrics.light_flash_highbeams | (enabled) | Momentarily overrides lights to highbeam. |
electrics.toggle_fog_lights | () , toggle_highbeams(), toggle_left_signal(), toggle_lightbar_signal(), toggle_right_signal(), toggle_warn_signal() | Direct input toggles for various light and signal systems. |
electrics.init | () / electrics.reset() | Initialization and reset hooks for electrical states and smoothers. |
electrics.updateGFX | (dt) | Primary update: calculates derived signals and syncs sensor data. |
electrics.updateGFXSecondStep | (dt) | Final pass update for ignition overrides and value smoothing. |
module.initLastStage | () | Final-stage initialization. |
Drivetrain Module Reference
Module defined in `lua/vehicle/drivetrain.lua`. Legacy compatibility proxy that mirrors modern powertrain and controller data into the old drivetrain API format. Exists to support older mods and scripts that read drivetrain state directly. New code should use the `powertrain` and `controller` modules instead.
Electrics Custom Value Parser
Module defined in `lua/vehicle/electricsCustomValueParser.lua`. Parses and evaluates custom expression-based electrics values defined in JBeam. Allows modders to create computed electrical signals using mathematical expressions that reference other electrics values.