Component
Generic access to every component the reflection registry describes: list, add, remove, read and write fields by name.
Namespace: caffeine.component · Dryad prefix: caffeine_component_
list#
Lua: caffeine.component.list · Dryad: caffeine_component_list
list() -> table
Lists every component type the reflection registry describes, with its fields. In Dryad it returns only the names.
Returns: table. Array of {name, id, fields}; each field has name, kind, min, max and options (enums).
Example
for _, c in ipairs(caffeine.component.list()) do caffeine.debug.log(c.name) end
names#
Lua: caffeine.component.names · Dryad: caffeine_component_names
names(entity) -> table
Lists the components the entity has. Errors when the entity does not exist.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
Returns: table. Array of component names.
Example
local names = caffeine.component.names(e)
has#
Lua: caffeine.component.has · Dryad: caffeine_component_has
has(entity, name) -> boolean
Checks whether an entity has a component. Errors on an unknown component name.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
Returns: boolean. True when the entity has the component.
Example
if caffeine.component.has(e, 'Rigid Body 3D') then end
add#
Lua: caffeine.component.add · Dryad: caffeine_component_add
add(entity, name) -> boolean
Adds a component with default values; does nothing if the entity already has it. In Dryad it returns false and logs an error on failure.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
Returns: boolean. true on success.
Example
caffeine.component.add(e, 'Rigid Body 3D')
remove#
Lua: caffeine.component.remove · Dryad: caffeine_component_remove
remove(entity, name) -> boolean
Removes a component from an entity.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
Returns: boolean. True when the component was removed, false when the entity did not have it.
Example
caffeine.component.remove(e, 'Rigid Body 3D')
get#
Lua: caffeine.component.get · Dryad: caffeine_component_get
get(entity, name) -> table|nil
Reads all fields of a component. Vectors are {x, y, z}; colours and 4D vectors also carry r, g, b, a; enums are option names.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
Returns: table. Table of every field, or nil when the entity lacks the component.
Example
local rb = caffeine.component.get(e, 'Rigid Body 3D')
getField#
Lua: caffeine.component.getField · Dryad: caffeine_component_get_field
getField(entity, name, field) -> any
Reads one field. Errors on an unknown component or field, or when the entity lacks the component (Dryad logs the error and returns null).
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
Returns: any. The field value.
Example
local mass = caffeine.component.getField(e, 'Rigid Body 3D', 'Mass')
setField#
Lua: caffeine.component.setField · Dryad: caffeine_component_set_field
setField(entity, name, field, value)
Writes one field. The entity must already have the component (use caffeine.component.add); a wrong value type raises an error.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
value | any | New value: number, boolean, text, enum option name or index, or a vector table. |
Returns: none
Example
caffeine.component.setField(e, 'Rigid Body 3D', 'Mass', 7.5)
set#
Lua: caffeine.component.set · Dryad: caffeine_component_set
set(entity, name, values)
Adds the component when missing and writes the given fields.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
values | table | Map of field name to value; omitted fields keep their value. |
Returns: none
Example
caffeine.component.set(e, 'Rigid Body 3D', { Mass = 3 })
caffeine_component_get_number#
Lua: not available · Dryad: caffeine_component_get_number
caffeine_component_get_number(entity, name, field[, index]) -> number
Dryad only: reads a numeric, boolean or enum field, or one part of a vector.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
index | integer | Vector part (0 = x); default 0. |
Returns: number. Number; integers, enum indices and bools come back as integer/boolean. null on error.
Example
let mass = caffeine_component_get_number(entity, "Rigid Body 3D", "Mass");
caffeine_component_set_number#
Lua: not available · Dryad: caffeine_component_set_number
caffeine_component_set_number(entity, name, field, value[, index]) -> boolean
Dryad only: writes a numeric, boolean or enum-index field, or one part of a vector.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
value | number | Number (or boolean). |
index | integer | Vector part (0 = x); default 0. |
Returns: boolean. True on success.
Example
caffeine_component_set_number(entity, "Rigid Body 3D", "Mass", 7.5);
caffeine_component_set_vec#
Lua: not available · Dryad: caffeine_component_set_vec
caffeine_component_set_vec(entity, name, field, x, y[, z[, w]]) -> boolean
Dryad only: writes a whole vector or colour field from its parts.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
x | number | First part. |
y | number | Second part. |
z | number | Third part (optional). |
w | number | Fourth part (optional). |
Returns: boolean. True when every part was written.
Example
caffeine_component_set_vec(entity, "Position 3D", "Position", 4, 5, 6);
caffeine_component_get_text#
Lua: not available · Dryad: caffeine_component_get_text
caffeine_component_get_text(entity, name, field) -> string
Dryad only: reads a string field or an enum option name.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
Returns: string. Text or enum label; null on error.
Example
let kind = caffeine_component_get_text(entity, "Mesh Filter", "Primitive");
caffeine_component_set_text#
Lua: not available · Dryad: caffeine_component_set_text
caffeine_component_set_text(entity, name, field, text) -> boolean
Dryad only: writes a string field or sets an enum by option name.
| Parameters | Type | Description |
|---|---|---|
entity | integer | Entity id. |
name | string | Component name as listed by `caffeine.component.list()`. |
field | string | Field name. |
text | string | Text or enum option name. |
Returns: boolean. True on success.
Example
caffeine_component_set_text(entity, "Mesh Filter", "Primitive", "Cone");