Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld b0f23b4e-e…

interact

What the player is looking at and can use. A registry of entities that answer to the interact key, a per-frame raycast from the player's camera that finds which one is under the reticle, and `current()` for the HUD to draw the prompt.

byPolar Night·posted 1mo ago
What it does

firstlight.interact

What the player is looking at and can use. A registry of entities that answer to the interact key, a per-frame raycast from the player's camera that finds which one is under the reticle, and current() for the HUD to draw the prompt.

local Interact = require("firstlight.interact")

API

CallWhat it does
Interact.register(entity, { label, onUse, key? })Make an entity usable. entity is a proxy or an id. label is a string, or a function returning the label for this moment — or nil when there is nothing to do right now (an empty crate, a trap already set), which hides the prompt. onUse runs on the interact key. key overrides the legend (default "E").
Interact.unregister(entity)Forget it.
Interact.current(){ label, key, entity, distance } for the target under the reticle within reach, or nil. The HUD draws the reticle prompt from this.
Interact.use()Use the current target. Returns whether something was used.
Interact.scan(camera, playerRoot)The per-frame raycast. firstlight.sites calls it every play frame from the local player's camera; nothing else needs to.
Interact.isRegistered(entity) / Interact.targets()Introspection.
Interact.REACH_MReach in metres (3).

A hit on any descendant of a registered entity counts as a hit on it, so a bundle's mesh children and a collider child resolve to the prop. Targets need a collider for the ray to find them; firstlight.sites fits an invisible interact_hit box to anything it registers that has none.

Registering from another slice

local stove = entity.find("stove")
Interact.register(stove, {
    label = function()
        return if Rules.state.hut.stoveOn then "Stoke stove" else "Light stove"
    end,
    onUse = function() stove.component.get("firstlight.stove"):light() end,
})

The interact key is the interact control of @builtin::inputMaps.default (E on a keyboard, the west face button on a pad, an on-screen button on a phone). firstlight.sites owns that subscription and calls Interact.use().

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

firstlight.interact — what the player is looking at and can use. A registry of entities that answer to the interact key, a per-frame scan that raycasts from the player's camera to find which one is under the reticle, and `current()` for the HUD to draw the prompt from. local Interact = require("firstlight.interact") Interact.register(stoveEntity, { label = "Light stove", onUse = function() stove:light() end }) Interact.unregister(stoveEntity) Interact.current() --> { label = "Light stove", key = "E", entity = "ent_…" } or nil `label` may be a function returning the label for this moment, or nil when the target has nothing to offer right now (an empty crate, a trap already set). A hit on any descendant of a registered entity counts as a hit on it, so a bundle's mesh children and a collider child all resolve to the prop.

idOf(e: any) → string

argtypedescription
eany

register(e: any, target: Target) → void

argtypedescription
eany
targetTarget

unregister(e: any) → void

argtypedescription
eany

isRegistered(e: any) → boolean

argtypedescription
eany

ownerOf(hitId: string) → void

Resolve a hit entity to the registered entity it belongs to, walking up parents.

argtypedescription
hitIdstring

labelOf(t: Target) → string

argtypedescription
tTarget

under(hitId: string, rootId: string?) → boolean

True when `hitId` is `rootId` or stands somewhere under it.

argtypedescription
hitIdstring
rootIdstring?

scan(camera: any, playerRoot: any?) → void

Raycast from `camera` (an entity proxy) along its forward and update `current()`. The sites component calls this every play frame. `playerRoot` is the local player's entity: the ray starts inside its own capsule, so hits on that hierarchy are passed over for the first thing beyond it. Scanning also opens a new interaction frame: `use()` acts at most once per scan, so however many key handlers call it on one press — one, or several left over from a hot reload — the press lands a single interaction.

argtypedescription
cameraany
playerRootany?

current( ) → void

The prompt under the reticle right now, or nil. The HUD draws from this.

use( ) → boolean

Use whatever is under the reticle. Returns true when something was used. The label is re-read here: a target whose label has gone nil (an empty crate, a trap already set) offers nothing, so its prompt is hidden AND its action is refused, even if `current` still names it from a frame the scan did not run in.

targets( ) → void

Every registered target, for tooling and tests.

⌬ Types
Target = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
This part has no composite children. See the Files segment for its leaf payloads.
backing path · firstlight/interact.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.