Reader
Based on game build 714014 | Last updated: 2026-03-03
Overview
Reader allows an entity to interact with books by reading them or perusing them. It maintains state for whether the entity is an aspiring bookworm, manages a custom sanity penalty multiplier, and supports a configurable callback for post-read logic. It adds and removes the reader and aspiring_bookworm tags on the owning entity as appropriate.
Usage example
local inst = CreateEntity()
inst:AddComponent("reader")
inst.components.reader:SetAspiringBookworm(true)
inst.components.reader:SetSanityPenaltyMultiplier(0.5)
inst.components.reader:SetOnReadFn(function(reader, book)
print("Book read successfully")
end)
Dependencies & tags
Components used: None (only uses external APIs like SpawnPrefab via book.components.book)
Tags: Adds reader on construction; adds/removes aspiring_bookworm based on state.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
aspiring_bookworm | boolean | false | Whether the entity is an aspiring bookworm (affects reading behavior). |
sanity_mult | number | 1 | Multiplier applied to sanity effects from reading. |
onread | function | nil | Optional callback invoked after successful reading. |
Main functions
SetAspiringBookworm(bookworm)
- Description: Sets whether the entity is an aspiring bookworm. When true, the entity peruses books instead of reading them fully.
- Parameters:
bookworm(boolean) -trueto set aspiring bookworm status. - Returns: Nothing.
IsAspiringBookworm()
- Description: Returns the current aspiring bookworm status.
- Parameters: None.
- Returns:
trueif aspiring bookworm, otherwisefalse.
SetSanityPenaltyMultiplier(mult)
- Description: Sets the multiplier used to scale sanity penalties when reading.
- Parameters:
mult(number) - the multiplier (e.g.,0.5halves sanity loss). - Returns: Nothing.
GetSanityPenaltyMultiplier()
- Description: Returns the current sanity penalty multiplier.
- Parameters: None.
- Returns: number - the multiplier (default
1if not set).
SetOnReadFn(fn)
- Description: Assigns a custom callback to run after a successful book read.
- Parameters:
fn(function) - function with signaturefn(reader, book). - Returns: Nothing.
Read(book)
- Description: Attempts to read (or peruse) a book, using the book's
bookcomponent logic. If the reader is an aspiring bookworm, only peruses; otherwise, reads fully and invokesonreadcallback if defined. - Parameters:
book(entity) - the book entity to read. - Returns:
- If aspiring:
true/false(result ofbook.components.book:OnPeruse). - If not aspiring:
success(boolean),reason(string, optional) frombook.components.book:OnRead.
- If aspiring:
- Error states: Returns
nilifbook.components.bookis missing or the book is unreadable.
Events & listeners
- Listens to: None.
- Pushes: None.
Notes
- The
readertag is automatically added on construction and removed on entity removal. - The
onaspiringbookwormcallback ensures theaspiring_bookwormtag stays in sync with the internal state.