Skip to main content

Digester

Based on game build 714014 | Last updated: 2026-03-03

Overview

The Digester component enables an entity to automatically consume (digest) one random non-irreplaceable item from its own inventory at a fixed time interval (digesttime, defaulting to 20 seconds). It is typically attached to entities that function as organic processing units (e.g., compost bins or biological digesters) and works in tandem with the inventory component. If no digestible items are present, the periodic task is automatically cancelled until a new item is added.

Usage example

local inst = CreateEntity()
inst:AddComponent("inventory")
inst:AddComponent("digester")
-- Optionally set a custom digestion predicate
inst.components.digester.itemstodigestfn = function(ent, item)
return item:HasTag("food")
end

Dependencies & tags

Components used: inventory Tags: Checks irreplaceable tag on individual items; does not manage entity-level tags.

Properties

PropertyTypeDefault ValueDescription
digesttimenumber20Interval in seconds between digest attempts.
itemstodigestfnfunction or nilnilOptional predicate function (entity, item) -> boolean that determines whether an item should be digestible. If nil, all non-irreplaceable items are digestible.
taskTask or nilnil (initialized after construction)The active periodic task for digest attempts; nil when no digest loop is running.

Main functions

TryDigest()

  • Description: Attempts to digest one item from the entity's inventory. It collects all digestible items (those without the irreplaceable tag, optionally filtered by itemstodigestfn), then consumes a random one using inventory:ConsumeByName. If no digestible items exist, it cancels the periodic task.
  • Parameters: None.
  • Returns: Nothing.
  • Error states: If self.inst.components.inventory is missing, the function does nothing and returns immediately. If no digestible items are found, the current periodic task (self.task) is cancelled and set to nil.

Events & listeners

  • Listens to: gotnewitem - Restarts the digest periodic task if it was previously cancelled due to empty inventory.
  • Pushes: None.