Simplebook
Overview
The Simplebook component enables an entity to act as a readable object (e.g., a book or note). When an entity with this component is "read" (typically via player interaction), it checks line-of-sight/visibility and, if valid, executes an optional callback function (onreadfn) provided externally. It also automatically adds and removes the "simplebook" tag on attachment/removal from an entity.
Dependencies & Tags
- Component Tags: Adds the
"simplebook"tag to the entity on initialization; removes it onOnRemoveFromEntity. - External Dependencies: Relies on the global function
CanEntitySeeTarget(doer, target)for visibility checks.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (assigned from constructor) | Reference to the owning entity. |
onreadfn | function? | nil | Optional callback function that executes when the book is read. Signature: function(inst, doer). Not initialized in the constructor but used by the Read method. |
Main Functions
Read(doer)
- Description: Handles the "read" action on the entity. First verifies that the
doer(e.g., a player) can see the book. If visible and anonreadfncallback is set, it invokes the callback with the book entity and thedoeras arguments. Returnsfalseif the action fails (e.g., not visible); otherwise returnsnil. - Parameters:
doer(Entity): The entity performing the read action (typically a player).
Events & Listeners
None.