Caffeine

Entity

Reference Core Last updated: Lua 5 · Dryad 4

Names and lookup. Entities are plain numeric ids; a name is optional and need not be unique.

All namespaces

Namespace: caffeine.entity · Dryad prefix: caffeine_entity_

name#

Lua: caffeine.entity.name · Dryad: caffeine_entity_name

text
name(entity) -> string

Reads the editor name of an entity.

ParametersTypeDescription
entitynumberThe entity id.

Returns: string. The name, or an empty string when unnamed or dead.

Example

lua
print(caffeine.entity.name(eid))

setName#

Lua: caffeine.entity.setName · Dryad: caffeine_entity_set_name

text
setName(entity, name) -> boolean

Names an entity so it can be found later.

ParametersTypeDescription
entitynumberThe entity id.
namestringNew name, at most 63 characters.

Returns: boolean. false when the entity is not alive.

Example

lua
caffeine.entity.setName(eid, "Boss")

find#

Lua: caffeine.entity.find · Dryad: caffeine_entity_find

text
find(name) -> number

Finds an entity by name.

ParametersTypeDescription
namestringExact name to look for.

Returns: number. The lowest matching entity id, or 0 when none.

Example

lua
local boss = caffeine.entity.find("Boss")

findAll#

Lua: caffeine.entity.findAll · Dryad: caffeine_entity_find_all

text
findAll(name) -> table

Finds every entity with a name.

ParametersTypeDescription
namestringExact name to look for.

Returns: table. Array of matching entity ids, ascending (empty when none).

Example

lua
for _, id in ipairs(caffeine.entity.findAll("Coin")) do caffeine.world.destroy(id) end

isAlive#

Lua: caffeine.entity.isAlive

text
isAlive(entity) -> boolean

Tells whether an id still refers to a live entity. Dryad: use caffeine_world_is_alive.

ParametersTypeDescription
entitynumberThe entity id.

Returns: boolean. true when the entity exists.

Example

lua
if caffeine.entity.isAlive(target) then end