About Don't Starve Together Game Scripts
This documentation is generated from the base scripts of Don't Starve Together, located at:
SteamLibrary\steamapps\common\Don't Starve Together\data\databundles\scripts.zip
Disclaimer: The information here may not be fully accurate and should be verified against the actual game files.
- A regularly updated and cleaned-up fork of the DST scripts: github.com/vietnd69/dst-scripts
- Contributions and fixes are welcome at: github.com/vietnd69/dst-api-webdocs
What Are DST Game Scripts?
Don't Starve Together is built on a comprehensive Lua scripting system that defines virtually every aspect of the game — mechanics, UI, AI, world generation, and mod support. Rather than a closed binary engine, DST exposes its logic through readable, moddable Lua scripts.
The scripts serve two roles simultaneously:
- Game Logic: The actual implementation of how DST works
- Mod Framework: The foundation community mods build on
Script System Architecture
Core Categories
| Category | Purpose | Examples |
|---|---|---|
| Components | Reusable behaviors attached to entities | health, inventory, combat, edible |
| Prefabs | Complete entity definitions (templates) | Characters, items, structures, creatures |
| Stategraphs | Animation and behavioral state machines | Player actions, creature movement |
| Brains | AI decision-making and goal selection | Creature AI, NPC behaviors |
| Behaviours | Reusable atomic AI actions | Approach, flee, wander, attack |
| Widgets | UI elements rendered in-game | Buttons, panels, HUD displays |
| Screens | Full-screen UI interfaces | Main menu, crafting UI, settings |
How Scripts Relate
Prefab (entity template)
├── Components ← what the entity CAN do
│ ├── health
│ ├── inventory
│ └── combat
├── Stategraph ← what the entity LOOKS like doing it
│ ├── idle
│ ├── walk
│ └── attack
└── Brain ← what the entity DECIDES to do
└── Behaviours ← individual AI actions
Interconnection Patterns
DST scripts are coupled through four mechanisms:
- Entity-Component: Prefabs compose behavior by attaching components
- Event System: Components communicate via
PushEvent/ListenForEvent, avoiding direct references - State Management: Stategraphs drive animations and trigger logic at specific animation frames
- AI Framework: Brains run a priority tree of Behaviours each tick to decide the entity's current action
File Organization
dst-scripts/
├── components/ # ~200+ reusable behaviors
├── prefabs/ # entity templates
├── stategraphs/ # animation state machines
├── brains/ # AI controllers
├── behaviours/ # atomic AI actions
├── widgets/ # HUD and UI elements
├── screens/ # full-screen interfaces
├── map/ # world generation
└── util/ # shared helpers
Common Patterns
Component
local MyComponent = Class(function(self, inst)
self.inst = inst
self.value = 0
end)
function MyComponent:SetValue(val)
self.value = val
self.inst:PushEvent("valuechanged", {value = val})
end
Event-Driven Communication
inst:ListenForEvent("healthdelta", function(inst, data)
if data.newpercent <= 0.25 then
inst:AddTag("lowhealth")
end
end)
Prefab Construction
local function fn()
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()
inst.entity:SetPristine()
if not TheWorld.ismastersim then return inst end
inst:AddComponent("health")
inst:AddComponent("inventory")
inst:AddComponent("combat")
inst.components.health:SetMaxHealth(100)
return inst
end
return Prefab("myentity", fn, assets)
Learning Path
Work through DST scripts in this order for the fastest mental model:
- Components — understand what behaviors exist and how they're structured
- Prefabs — see how components combine into complete entities; learn the
ismastersimserver/client split - Stategraphs — understand how animations and code interact via timeline events
- Brains + Behaviours — learn how AI decisions are layered and prioritized
Auto-docs — Documentation Generator
This documentation is generated automatically by Auto-docs, an open-source tool that analyzes DST Lua source files and produces Markdown documentation using AI.
- Best results with qwen3.5 (recommended model)
- Supports multi-account load balancing, chunked processing for large files, and built-in validation
- Contributions and feedback are very welcome — if you'd like to help develop the project, please visit github.com/vietnd69/Auto-docs
Contributing
Found inaccurate information or missing coverage? The documentation is open for contributions:
- Open an issue or PR at github.com/vietnd69/dst-api-webdocs
- Reference the actual script source to verify correctness
- Practical examples and edge-case notes are especially valuable