Builtin Library
README.md
Slot
A named place on an entity that another part fills: a wheel mount, an engine
bay, a seat, a weapon hardpoint, a socket in a modular wall, a mount on a ship.
The entity carrying Slot is where the part attaches: the part is built as a
child of that entity and stands at its transform. Put a Slot on an empty
child positioned where the part goes, one per slot.
What fills the slot is held by the Assembly on the slot's root (the nearest
Assembly on the entity or above it; one on a part built into a slot passes
the slot on to the Assembly holding that part), by the slot's path. A slot
under no Assembly holds its default.
Fields
| Field | Type | Notes |
|---|---|---|
name | string | The name the slot answers to in paths; empty takes the entity's name. |
kind | string | The kind of part it takes (wheel, engine, seat). A part fits when its Part.fits names this kind. Empty takes any part. |
tags | { string } | Asset tags a part must carry, all of them, to fit. |
default | instantiable asset | The part filling the slot when its Assembly names none. |
joint | table | Joint fields binding the part's body to the body the slot stands on ({ kind = "hinge", axis = { 1, 0, 0 } }); the Joint component on the part's root is added with connected set to the slot. Empty seats the part as a child alone. |
Paths
A slot's path is its name, under the path of the slot whose part it stands in:
an engine part carrying a turbo slot, filled into the engine slot, puts
that slot at engine/turbo. Paths are what Assembly:fill, Assembly:resolve
and the saved configuration use.
Methods
| Method | Returns | Notes |
|---|---|---|
:path() | string | This slot's path in its Assembly. |
:assembly() | Assembly or nil | The Assembly that holds it. |
:fill(part) | entity or nil | Fill through the Assembly (Assembly:fill(self:path(), part)); raises when the part does not fit, naming why. |
:empty() | Leave it empty, its default included. | |
:fits(part) | (boolean, string) | Whether a part fits, and why or why not. |
:filled() | { part, entity, source } or nil | The part filling it and the entity it was built on. |
:refresh() | entity or nil | Rebuild the part when it differs from what the Assembly names. |
Usage
-- A body with a wheel slot and an engine slot
local body = entity.spawn("buggy")
body.component.add("Assembly")
local fl = entity.spawn("wheel_fl", { parent = body.id, position = { x = -0.8, y = 0.3, z = 1.2 } })
fl.component.add("Slot", { kind = "wheel", default = "parts.StockWheel" })
local bay = entity.spawn("engine", { parent = body.id, position = { x = 0, y = 0.5, z = 1 } })
bay.component.add("Slot", { kind = "engine" })
bay.component.get("Slot"):fill("parts.V8")
print(fl.component.get("Slot"):fits("parts.V8")) -- false, "slot 'wheel_fl' takes parts of kind 'wheel'; 'parts.V8' fits { engine }"
Put the same children in a bundle (asset.create("bundle", "Buggy", { entity = body }))
and every instance of the bundle carries the slots. The Assembly README
covers configurations, the resolver, undo, multiplayer and saving.