Skip to content

Engine Lua API

The engine is controlled from CC:Tweaked through the ccpe:engine peripheral. Wrap any core segment — the peripheral lives on the engine's controller and non-controller segments delegate to it:

local e = peripheral.wrap("front")
-- or: peripheral.find("ccpe:engine")

Scripts on a physics body: grab it from ccpe.sensor_system instead

When the computer sits on a physics body (Sable sub-level), you can get the engine peripheral straight from the sensor module:

local ss = require("ccpe.sensor_system")
local e = ss.getEngine()   -- exactly one engine on the single body the computer sits on (constraint chain excluded) → its peripheral; otherwise nil
  • Scope = the one physics body the computer sits on (a single Sable sub-level), constraint chain excluded: engines on other sub-levels of the chain (another segment linked by bearings) are neither counted nor returned — to drive the engine on that segment, call this from the computer on that segment.
  • No peripheral-network reachability needed — the engine can be any distance from the computer.
  • Only returns a peripheral when that body has exactly one engine; no engine there, or ≥2 engines (twin/multi-engine craft) → nil, so keep using peripheral.wrap / peripheral.find per engine there.
  • Resolved at call time (mainThread = true, one main-thread hop per call, at most 1 tick stale) and no cached peripheral reference: after the engine is broken/reformed/extended it returns nil instead of a stale object. Call it once at the top of your script and keep the result in a local.

Example — Temperature and Mixture Control

The engine already ships with built-in temperature & mixture auto control (no script needed) — see Auto Control. The methods below are for writing your own control loop (call setAutoControl(false) first).

Reading vs writing

  • Read methods run with mainThread=false and read the controller's cached state directly — at most 1 tick stale, and effectively free to poll at high frequency.
  • Write methods and getFluidTanks() run with mainThread=true (server-authoritative, scans the world).

Methods

Method mainThread Returns Description
getTemperature() false number Engine temperature in °C
isOverheated() false boolean Overheat lock (fluid engines only; hard-stop at T≥220°C, unlock at T≤200°C)
getFluidTanks() true table[] All connected fluid tanks: {fluid, amount, remaining, capacity} (fluid is nil when empty)
getThrottle() false number Throttle 0..1 (default 1.0 = 100%, 256 rpm). Sets the output speed only (speed = throttle × 256 rpm; stress capacity is constant; 0 = stopped, no fuel burned; the only on/off control)
getLoad() false number Load 0..1 = stress network's "stress used / capacity available" (actual value, idle floor not included; 0 when idle, 0 when stopped). The driver of fuel burn and heat — handy for economy scheduling
getStressUsed() false number Stress used by the network (SU, whole network: Σ machine impact × speed; stopped/unattached → 0)
getStressCapacity() false number Capacity available on the network (SU, whole network; this engine's own contribution is constant = 8192 per fluid chamber / 4096 per steam chamber)
setThrottle(0..1) true boolean Set throttle (clamped; returns false on invalid input). Changes speed only, never the stress capacity; fuel consumption follows the load
isReversed() / setReversed(bool) false/true boolean Output direction: false = forward (default), true = reversed. Only the direction flips — speed magnitude, stress capacity, load, fuel burn and heat are all unchanged (the whole kinetic network is driven the other way, so downstream machines spin backwards); pure stored value, NBT-persisted (survives rebuild/reload). The engine core's Current Speed goggle line shows a negative value while reversed
getMixture() false number Mixture lever 0.6..1.4 (fluid engines only; steam is always 1.0). Affects fuel cost and heat at a given load
setMixture(x) true boolean Mixture: fuel × lever, temperature × heat factor; no gating (pure storage — no effect on non-fluid engines)
getEffectiveMixture() false number Actual mixture = lever × altitude auto-rich (used by the economy window and heat feedback; > lever at altitude)
getAutoRichness() false number Natural altitude mixture = the altitude auto-rich/lean coefficient only (no lever): 1.0 at sea level, up to ×1.25 at high altitude, down to ×0.75 below sea level (auto-lean at high pressure) (steam: always 1.0). Reference for how far to pull the lever — pull to ≈ 1 / getAutoRichness() so m_eff ≈ 1.0
getFuelEconomyFactor() false number Economy factor 0.75..1.0 (temperature + mixture both in window, ramps in over 15 s; wrong mixture = no reward, no penalty)
hasAirDuct() false boolean Whether a cooling air duct is installed (informational; setMixture/setCooling are ungated — the shutter value is only consumed when a duct is present)
getActiveFuel() false table Active fuel: fluid {type="fluid", fluid=<id>, optimalTemp=155}; steam {type="steam", optimalTemp=155}; stopped {type="none"}
getCooling() false number Cooling shutter 0..1 (default 1.0)
setCooling(0..1) true boolean Shutter: only scales the duct dissipation component, can only reduce; no gating (pure storage, consumed only with a duct installed)
hasWaterCooling() false boolean Whether a water cooling module is installed (see Water Cooling Module)
getWaterCooling() false number Water loop opening 0..1 (default 1.0)
setWaterCooling(0~1) true boolean Water loop opening: only scales the water k_water component; 0 = closed loop (no cooling, and no coolant evaporation); no gating (pure storage, no effect without a module)
getWaterCoolingPower() false number Current effective water dissipation k_water (amount ratio × coolant efficiency × opening; immune to ram air and pressure)
getWaterCoolingModules() false number Number of working water cooling modules (coolant amount > 0)
getCoolantAmount() false number Total coolant in mB (sum over working modules; server-synced value)
getWaterCoolingStress() false number Stress tied up by the water modules (= working modules × 512) — really applied to the network, see Water Cooling Module
getAutoControl() false boolean Whether the built-in auto control is on (default on): the engine holds 155°C and an effective mixture of 0.9 by itself. See Auto Control
setAutoControl(bool) true boolean Explicitly toggle auto control (resets the integral / enrichment state when enabling). Calling any of setMixture / setCooling / setWaterCooling turns it off automatically and hands control back to the player
isWarmingUp() false boolean Steam warm-up in progress (T<100°C burns without generating)

Status tiers (fluid engine, via getTemperature())

The tier is decided by load vs cooling: more load = hotter, better cooling (ducts / shutter / ram air / low altitude) = cooler. To cool down, drop the load or improve the cooling.

Temperature Status
— (not running) Stopped
< ~97°C Cold (fuel penalty)
97 ~ 145°C Normal
145 ~ 165°C Efficient (economy band)
165 ~ 200°C Normal
200 ~ <220°C Getting hot
≥ 220°C Overheated