Phonograph
Based on game build 722832 | Last updated: 2026-04-21
Overview
The phonograph prefab defines a decorative structure capable of playing music records. When active, it emits sound and periodically tends to nearby farm plants within a specific range. It functions as a trader accepting record items, and can be destroyed via hammering to drop loot and spawn collapse effects.
Usage example
-- Spawn a phonograph in the world
local phonograph = SpawnPrefab("phonograph")
-- Check if it is currently enabled
local is_enabled = phonograph.components.machine.enabled
-- Manually trigger record playback logic if a record is inserted
phonograph:TryToPlayRecord()
-- Force stop playing and turn off machine
phonograph:StopPlayingRecord()
Dependencies & tags
External dependencies:
TUNING-- accessesPHONOGRAPH_TEND_RANGEandPHONOGRAPH_PLAY_TIMEACTIONS-- referencesHAMMERaction for workable componentSpawnPrefab-- spawnscollapse_smallfx on destruction
Components used:
inventory-- manages inserted record items viaDropEverything,GiveItem,NumItems,GetItemsWithTaginventoryitem-- checks ownership viaIsHeld, sets put/drop callbacksmachine-- controls power state viaTurnOn,TurnOff,IsOn,enabledlootdropper-- spawns loot viaDropLooton hammertrader-- handles item acceptance viaSetAcceptTest,onacceptworkable-- configures hammering viaSetWorkAction,SetOnFinishCallbackfurnituredecor-- marks entity as decorative furnitureinspectable-- allows player inspectionhauntable-- enables ghost haunting interactions
Tags:
structure-- added on creationtrader-- added on creationrecordplayer-- added on creationfurnituredecor-- added on creationgroundonlymachine-- added on creationtendable_farmplant-- checked viaFindEntitiesfor farming effectphonograph_record-- checked viaHasTag/GetItemsWithTagfor record validation
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
components.machine.enabled | boolean | false | Determines if the machine is allowed to operate and play songs. |
_play_song_task | taskref | nil | Internal reference to the delayed task playing the song. |
_stop_song_task | taskref | nil | Internal reference to the task scheduled to stop the song. |
_tend_update_task | taskref | nil | Internal reference to the periodic task tending nearby plants. |
Main functions
DropRecord()
- Description: Drops the current record item from inventory and disables the machine. Called when inserting a new record or removing the old one.
- Parameters: None
- Returns: None
- Error states: Errors if
components.machineorcomponents.inventoryis missing (no nil guard present).
OnHammered(worker)
- Description: Callback executed when the phonograph is hammered. Drops loot, spawns collapse fx, and removes the entity.
- Parameters:
worker-- The entity performing the hammer action.
- Returns: None
- Error states: Errors if
components.lootdropperis missing (nil dereference). May crash ifcollapse_smallprefab does not exist (fx would be nil before Transform access).
ShouldAcceptItem(item)
- Description: Test function for the trader component to validate if an item can be inserted.
- Parameters:
item-- The item entity being offered.
- Returns:
trueif item hasphonograph_recordtag, otherwisenil. - Error states: None
OnGetItemFromPlayer(giver, item)
- Description: Callback when a player successfully trades a record to the phonograph. Drops existing record, accepts new one, and turns machine on.
- Parameters:
giver-- The player entity giving the item.item-- The record item entity.
- Returns: None
- Error states: Errors if
components.inventoryorcomponents.machineis missing.
GetRecordSong()
- Description: Retrieves the song identifier from the currently held record item.
- Parameters: None
- Returns: String song name or
nilif no record is found. - Error states: Errors if
components.inventoryis missing.
TryToPlayRecord()
- Description: Attempts to start playing the record. Checks if held and if a song exists. Enables machine and starts animation/tasks.
- Parameters: None
- Returns: None
- Error states: Errors if
components.inventoryitem,components.machine, orAnimStateis missing.
StopPlayingRecord()
- Description: Stops the current song, cancels tasks, resets animation, and plays stop sound. Pushes
turnedoffevent. - Parameters: None
- Returns: None
- Error states: Errors if
SoundEmitterorAnimStateis missing.
TurnOffMachine()
- Description: Helper function to safely turn off the machine component.
- Parameters: None
- Returns: None
- Error states: None
OnPutInInventory(owner)
- Description: Callback when the phonograph itself is picked up. Turns off the machine if it was playing.
- Parameters:
owner-- The entity picking up the phonograph.
- Returns: None
- Error states: Errors if
components.machineis missing.
OnDroppedFromInventory()
- Description: Callback when the phonograph is dropped from inventory. Re-enables machine if inventory has items.
- Parameters: None
- Returns: None
- Error states: Errors if
components.inventoryorcomponents.machineis missing.
OnLoad(data)
- Description: Load callback to restore machine enabled state based on inventory contents.
- Parameters:
data-- Save data table (unused in logic but required signature).
- Returns: None
- Error states: Errors if
components.inventoryorcomponents.machineis missing.
Events & listeners
- Listens to: None directly via
ListenForEvent. Relies on component callbacks (inventoryitem,machine,workable,trader). - Pushes:
turnedoff- Fired whenStopPlayingRecordcompletes the shutdown sequence.