Skip to main content

Last Update: 2023-07-06

Setting Up VSCode for DST Modding

Visual Studio Code (VSCode) is a powerful, lightweight code editor that works well for Don't Starve Together mod development. This guide will walk you through setting up VSCode with extensions and configurations specifically tailored for DST modding.

Why Use VSCode for DST Modding?

  • Lua Support: Built-in syntax highlighting and formatting for Lua files
  • Extensions: Rich ecosystem of extensions for DST modding
  • Integrated Terminal: Run and test mods directly from the editor
  • Git Integration: Version control your mods easily
  • Customizable: Adapt the editor to your workflow
  • Free and Cross-Platform: Works on Windows, macOS, and Linux

Installation

  1. Download and install VSCode from the official website
  2. Launch VSCode after installation

Essential Extensions for DST Modding

1. Lua Language Support

Install the Lua language extension to get syntax highlighting, code completion, and linting for Lua files:

  1. Open the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS)
  2. Search for "Lua"
  3. Install "Lua" by sumneko

2. DST API Extension

The Don't Starve Together API extension provides autocompletion and documentation for DST's API:

  1. Open the Extensions view
  2. Search for "dst-lan"
  3. Install "Don't Starve Together API Complete Extension"

This extension is maintained on GitHub: b1inkie/dst-api

3. Lua Debug

For debugging your mods:

  1. Open the Extensions view
  2. Search for "Local Lua Debugger"
  3. Install "Local Lua Debugger" by tomblind

Configuring VSCode for DST Modding

Workspace Settings

Create a .vscode folder in your mod directory and add a settings.json file with these recommended settings:

{
"Lua.diagnostics.globals": [
"GLOBAL",
"TheWorld",
"ThePlayer",
"TheNet",
"TheSim",
"TUNING",
"STRINGS",
"ACTIONS",
"EQUIPSLOTS",
"RECIPETABS",
"TECH",
"SpawnPrefab",
"CreateEntity",
"AddComponent"
],
"Lua.workspace.library": [
// Add path to your DST installation's scripts directory
"[Steam Directory]/steamapps/common/Don't Starve Together/data/scripts"
],
"Lua.workspace.preloadFileSize": 1000,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.encoding": "utf8",
"files.trimTrailingWhitespace": true
}

Note: Adjust the path to your DST installation as needed.

Snippets

Create a lua.json file in the .vscode folder with useful snippets for DST modding:

{
"Create Basic Prefab": {
"prefix": "dstprefab",
"body": [
"local assets = {",
" -- Add your assets here",
"}",
"",
"local prefabs = {",
" -- Add your prefabs here",
"}",
"",
"local function fn()",
" local inst = CreateEntity()",
" ",
" inst.entity:AddTransform()",
" inst.entity:AddAnimState()",
" inst.entity:AddNetwork()",
" ",
" MakeInventoryPhysics(inst)",
" ",
" inst.AnimState:SetBank(\"${1:bank}\")",
" inst.AnimState:SetBuild(\"${2:build}\")",
" inst.AnimState:PlayAnimation(\"${3:idle}\")",
" ",
" inst.entity:SetPristine()",
" ",
" if not TheWorld.ismastersim then",
" return inst",
" end",
" ",
" inst:AddComponent(\"inspectable\")",
" inst:AddComponent(\"inventoryitem\")",
" ",
" return inst",
"end",
"",
"return Prefab(\"${4:prefab_name}\", fn, assets, prefabs)"
],
"description": "Creates a basic DST prefab template"
},
"Add Component": {
"prefix": "dstcomponent",
"body": [
"inst:AddComponent(\"${1:component}\")",
"inst.components.${1:component}:${2:SetSomeProperty}(${3:value})"
],
"description": "Adds a component to an entity"
}
}

Setting Up Your Mod Project

Folder Structure

Create a consistent folder structure for your mods:

my_mod/
├── modinfo.lua # Mod metadata
├── modmain.lua # Main mod file
├── scripts/ # Custom scripts
│ ├── prefabs/ # Custom prefabs
│ ├── components/ # Custom components
│ └── widgets/ # Custom UI widgets
├── anim/ # Custom animations
├── images/ # Images and icons
└── .vscode/ # VSCode configuration
├── settings.json
└── lua.json

Linking to Your DST Mods Folder

For easier testing, you can create a symbolic link from your development folder to the DST mods folder:

Windows:

mklink /D "C:\Program Files (x86)\Steam\steamapps\common\Don't Starve Together\mods\my_mod" "C:\path\to\your\development\my_mod"

macOS/Linux:

ln -s /path/to/your/development/my_mod "/path/to/steam/steamapps/common/Don't Starve Together/mods/my_mod"

Useful VSCode Keyboard Shortcuts

ActionWindowsmacOS
Open Command PaletteCtrl+Shift+PCmd+Shift+P
Quick Open FileCtrl+PCmd+P
Find in FilesCtrl+Shift+FCmd+Shift+F
Toggle TerminalCtrl+`Cmd+`
Format DocumentShift+Alt+FShift+Option+F
Go to DefinitionF12F12
Rename SymbolF2F2

Troubleshooting

Lua Language Server Issues

If you encounter issues with the Lua language server:

  1. Reload VSCode (Ctrl+Shift+P > "Developer: Reload Window")
  2. Check if your Lua path is correctly set in settings.json
  3. Make sure your DST scripts path exists and is accessible

Extension Not Working

If the DST API extension isn't working:

  1. Make sure you have the latest version of VSCode (1.73.0+)
  2. Check the extension's output channel for errors
  3. Try reinstalling the extension

Additional Resources

See also