Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

prefab.link (procNode)

Reference one prefab entity from another through a component field, by stable id, so the reference survives instantiation (constraint targets, look-at goals, trigger to door, switch to light, portal pairs).

The value written is the record id of to (the root's is "0", an added entity's add_<n>). Built from prefab.edit (what = "link").

Inputs

  • prefab (Prefab). Both ends live inside this one prefab: from and to name entities it already carries, so the value written is a record id belonging to this record list.
  • from (String, default ""). The name of the entity that holds the reference: the switch, the constraint, the trigger. The first record carrying the name is the one written to; a name the prefab does not carry is an error.
  • to (String, default ""). The name of the entity pointed at: the door the trigger opens, the light the switch drives. Its record id is the value written; a name the prefab does not carry is an error. Swapping this with from reverses which end holds the reference.
  • type (String, default ""). The component on from the reference is written into. The first component of that type is used, and one carrying an empty data table is added when from holds none. Required: an empty type is an error.
  • field (String, default "target"). The key inside that component's data the referenced entity's record id lands under, which lets one component hold several references, each under its own key. An empty string takes "target".

Outputs

  • prefab (Prefab). A new prefab value, { records = { ... } }; the prefab wired in keeps the records it had.
local room = g.prefab.empty({ name = "room" })
room = g.prefab.entity({ prefab = room, name = "switch" })
room = g.prefab.entity({ prefab = room, name = "lamp" })
room = g.prefab.link({ prefab = room, from = "switch", to = "lamp", type = "Switch" })