Skip to main content

About Don't Starve Together Game Scripts

AI-Generated Documentation

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.

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

CategoryPurposeExamples
ComponentsReusable behaviors attached to entitieshealth, inventory, combat, edible
PrefabsComplete entity definitions (templates)Characters, items, structures, creatures
StategraphsAnimation and behavioral state machinesPlayer actions, creature movement
BrainsAI decision-making and goal selectionCreature AI, NPC behaviors
BehavioursReusable atomic AI actionsApproach, flee, wander, attack
WidgetsUI elements rendered in-gameButtons, panels, HUD displays
ScreensFull-screen UI interfacesMain 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:

  1. Entity-Component: Prefabs compose behavior by attaching components
  2. Event System: Components communicate via PushEvent / ListenForEvent, avoiding direct references
  3. State Management: Stategraphs drive animations and trigger logic at specific animation frames
  4. 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:

  1. Components — understand what behaviors exist and how they're structured
  2. Prefabs — see how components combine into complete entities; learn the ismastersim server/client split
  3. Stategraphs — understand how animations and code interact via timeline events
  4. 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