Fertilizerresearchable
Based on game build 714014 | Last updated: 2026-03-03
Overview
FertilizerResearchable allows an entity to expose metadata about a specific fertilizer type that players can discover through the research system. It is attached to static world objects (e.g., compost bins) and integrates with the learnfertilizer event flow during player interaction. The component ensures the target entity is tagged fertilizerresearchable, marking it as a valid source for fertilizer research.
Usage example
local inst = CreateEntity()
inst:AddComponent("fertilizerresearchable")
inst.components.fertilizerresearchable:SetResearchFn(function(ent)
return "rotgut"
end)
-- Later, when a player interacts with the entity:
inst.components.fertilizerresearchable:LearnFertilizer(player)
Dependencies & tags
Components used: None identified
Tags: Adds fertilizerresearchable
Properties
No public properties
Main functions
SetResearchFn(fn)
- Description: Assigns a callback function that returns the fertilizer identifier when invoked. This function is called during research to determine which fertilizer the entity provides.
- Parameters:
fn(function) — A function taking the entity instance as its only argument and returning a string fertilizer name (e.g.,"rotgut"), ornil. - Returns: Nothing.
GetResearchInfo()
- Description: Invokes the research function (if set) and returns the resulting fertilizer identifier.
- Parameters: None.
- Returns:
string?— The fertilizer name, ornilif no research function is defined or the function returnsnil. - Error states: Returns
nilifself.reasearchinfofnis unset.
LearnFertilizer(doer)
- Description: Triggers the
learnfertilizerevent on thedoer(typically a player entity), delivering the fertilizer data obtained viaGetResearchInfo(). Used when a player interacts with the researchable entity to learn a new fertilizer recipe. - Parameters:
doer(GObject) — The entity (usually a player) performing the action and receiving the event. - Returns: Nothing.
- Error states: Does nothing if
GetResearchInfo()returnsnil.
Events & listeners
- Listens to: None
- Pushes:
learnfertilizer— Fired on thedoerentity with payload{ fertilizer = "..." }when fertilizer is successfully learned.