Debugkeys
Based on game build 714014 | Last updated: 2026-03-21
Overview
The debugkeys module provides a comprehensive framework for development and testing within Don't Starve Together. It registers global and gameplay-specific keyboard shortcuts to manipulate simulation parameters, entity states, and world topology. Key features include console command wrappers for spawning and removing entities, direct component manipulation (health, hunger, sanity), map tile editing, and simulation control (pause, step, time scale). It also handles mouse debug actions for entity inspection and removal, and facilitates remote command execution between client and server. This module is essential for developers needing to rapidly iterate on game mechanics or verify entity behaviors without standard gameplay constraints.
Usage example
-- Register a global debug key to print player position
AddGlobalDebugKey(KEYS.F5, function()
if ThePlayer then
local pos = ThePlayer.Transform:GetWorldPosition()
print("Player at:", pos.x, pos.y, pos.z)
end
end)
-- Spawn a beefalo using the debug wrapper
d_c_spawn("beefalo", 1)
-- Teleport player to mouse position
DebugKeyHandler_T()
-- Force next hounded wave
DebugKeyHandler_H()
Dependencies & tags
External dependencies:
TheWorld-- Accessed for simulation state, topology, and event pushingTheSim-- Used for debug pause, stepping, and entity findingTheInput-- Used for key state checks and mouse positionTheFrontEnd-- Used to toggle debug panels and UITheInventory-- Used for debug gift functionsConsoleCommandPlayer-- Called to get the player entity for commandsGLOBAL-- Used to expose global variablesProfile-- Checked for threaded render settingVector3-- Used for coordinate calculationsSpawnPrefab-- Called to instantiate entitiesConsoleRemote-- Called to execute commands on server from clientconsolecommands-- Required for console command functionsscripts/reload.lua-- Required and reloaded for hot-reload functionalitydbui_no_package-- Conditionally required for debug UI modulesThePlayer-- Used to access local player components and positionTheCamera-- Used to access target position and headingTUNING-- Used to access game balance constants like TOTAL_DAY_TIMEEnts-- Iterated to find specific prefabs in the worldDebugKeyPlayer-- Called to get the debug key player instancePostProcessor-- Used to set colour cube datarequire-- Used to load map/levels, map/tasks, map/tasksets, map/rooms, prefabs/skilltree_defsusercommands-- Required to run user commands for emotes
Components used:
domesticatable-- Accessed to print tendencies on beefalohealth-- Accessed to modify health on boat bumpersinventory-- Accessed to equip items on console playertransform-- Used to set entity positionsnetwork-- Used to get network ID for remote removalsanity-- Accessed to modify sanity via DoDelta or SetPercenthunger-- Accessed to modify hunger via DoDeltatemperature-- Referenced for debug delta modificationpickable-- Accessed to Pick or Regen plantsfueled-- Accessed to SetPercent fuelharvestable-- Accessed to Grow producegrowable-- Accessed to DoGrowthperishable-- Accessed to Perish itemsetter-- Accessed to SetSetTime and StartSettingcooldown-- Accessed to LongUpdatelocomotor-- Checked for teleport target validationwalkableplatform-- Accessed to get players on boat platforminventoryitem-- Accessed to SetLanded stateherdmember-- Accessed to find herd associationherd-- Accessed to iterate membersperiodicspawner-- Accessed to TrySpawnmood-- Accessed to SetIsInMoodknownlocations-- Accessed to GetLocationhounded-- Accessed to ForceNextWaveskilltreeupdater-- Accessed to manage skill XP and activationfarming_manager-- Accessed via TheWorld.components to get and add tile nutrientsTransform-- Used to get world position or set entity positionMap-- Used to get tile coordinates, tile type, and set tile typeHUD-- Accessed on ThePlayer to toggle visibility
Tags:
player-- checkboatbumper-- checkFX-- checkNOCLICK-- checkDECOR-- checkINLIMBO-- check_inventoryitem-- checkwall-- check
Properties
| Property | Type | Default Value | Description |
|---|
Main functions
dumpvariabletostr(var)
- Description: Converts a variable to a string format using type-specific formatting functions.
- Parameters:
var-- The variable to convert to a string representation
- Returns: string representation of the variable
- Error states: Asserts if the type is not found in fcts table
d_c_spawn(prefab, count, dontselect)
- Description: Wrapper for c_spawn that handles network replication for client/server.
- Parameters:
prefab-- String name of the prefab to spawncount-- Number of entities to spawndontselect-- Boolean flag to prevent auto-selection
- Returns: nil
d_c_give(prefab, count, dontselect)
- Description: Wrapper for c_give that handles network replication for client/server.
- Parameters:
prefab-- String name of the prefab to givecount-- Number of items to givedontselect-- Boolean flag to prevent auto-selection
- Returns: nil
d_c_remove(entity)
- Description: Removes an entity, handling network ID serialization for remote execution.
- Parameters:
entity-- Entity instance to remove, defaults to mouse entity
- Returns: nil
- Error states: Returns early if world or mouse entity is nil
d_c_removeall(entity)
- Description: Removes all entities of the same prefab type.
- Parameters:
entity-- Entity instance to match for removal, defaults to mouse entity
- Returns: nil
DebugKeyPlayer()
- Description: Retrieves the console command player entity if on master server.
- Parameters: None
- Returns: Entity or nil
- Error states: Returns nil if not master sim or no player
DoDebugKey(key, down)
- Description: Iterates through registered handlers for a specific key and executes them.
- Parameters:
key-- Key code identifierdown-- Boolean indicating key press state
- Returns: true if handled, nil otherwise
AddGameDebugKey(key, fn, down)
- Description: Registers a debug key handler that only activates during gameplay.
- Parameters:
key-- Key code identifierfn-- Function to execute on key eventdown-- Boolean indicating whether to trigger on key down (default true)
- Returns: nil
AddGlobalDebugKey(key, fn, down)
- Description: Registers a debug key handler that activates globally regardless of game state.
- Parameters:
key-- Key code identifierfn-- Function to execute on key eventdown-- Boolean indicating whether to trigger on key down (default true)
- Returns: nil
SimBreakPoint()
- Description: Toggles the simulation debug pause state.
- Parameters: None
- Returns: nil
DoDebugMouse(button, down, x, y)
- Description: Routes mouse button events to corresponding debug handler functions.
- Parameters:
button-- number, mouse button identifier (MOUSEBUTTON_RIGHT or MOUSEBUTTON_LEFT)down-- boolean, true if mouse button is pressedx-- number, mouse x coordinatey-- number, mouse y coordinate
- Returns: false if not down, otherwise nil
- Error states: Returns false immediately if down is false
DoReload()
- Description: Reloads the scripts/reload.lua module to refresh debug scripts.
- Parameters: None
- Returns: nil
Spawn(prefab)
- Description: Helper function to spawn a prefab entity.
- Parameters:
prefab-- String name of the prefab to spawn
- Returns: Entity instance
BindKeys(bindings)
- Description: Iterates through a binding table and registers keys using AddGlobalDebugKey.
- Parameters:
bindings-- Table of key binding configurations
- Returns: nil
try_boat_teleport(boat, x, y, z)
- Description: Teleports a boat entity and its attached items to a new position, handling physics and platform updates.
- Parameters:
boat-- Entity instance of the boat to teleportx-- Number, target X coordinatey-- Number, target Y coordinatez-- Number, target Z coordinate
- Returns: boolean, true if successful
DebugKeyHandler_PAGEUP()
- Description: Increases wetness, moisture, snow level, or advances season based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_PAGEDOWN()
- Description: Decreases wetness, moisture, snow level, or retreats season based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_O()
- Description: Scans map levels, tasks, and rooms for specific tags like Chester_Eyebone when Shift is held.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_F9()
- Description: Triggers a LongUpdate with 25% of total day time.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_F11()
- Description: Automatically picks all planted carrot entities in the world.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_1()
- Description: Teleports the main character to the next teleportato part location when Ctrl is held.
- Parameters: None
- Returns: boolean, true or nil
- Error states: Returns nil if Ctrl is not held
DebugKeyHandler_X()
- Description: Selects the entity under the mouse or equips the player's hand item when Ctrl is held.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_LEFTBRACKET()
- Description: Adjusts simulation time scale or resets player skill tree XP based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_RIGHTBRACKET()
- Description: Adjusts simulation time scale or adds skill tree XP based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_KP_PLUS()
- Description: Increases player health, hunger, or sanity via remote commands or direct component calls.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_KP_MINUS()
- Description: Decreases player health, hunger, or sanity via remote commands or direct component calls.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_T()
- Description: Teleports the player or selected entity to the mouse map position, handling boat platforms.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_G()
- Description: Triggers growth, fuel, harvest, regen, perish, setting, cooldown, or domestication on the mouse entity when Ctrl is held.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_D()
- Description: Prepares to modify map tiles at the world position under the mouse when Shift is held.
- Parameters: None
- Returns: None
DebugKeyHandler_K()
- Description: Removes selected entity or teleports to monkeyhut based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_L()
- Description: Prints map node and tile information around the player or resets loading widget if no world.
- Parameters: None
- Returns: None
- Error states: Returns early if ThePlayer is nil
DebugKeyHandler_KP_DIVIDE_GLOBAL()
- Description: Toggles frame profiler or debug texture visibility based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_EQUALS()
- Description: Updates debug texture value or increments map overlay lerp value.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_MINUS()
- Description: Updates debug texture value or decrements map overlay lerp value.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_M()
- Description: Toggles fog of war, revealed areas, or reveals entire map based on modifier keys.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_N()
- Description: Teleports player to the next node.
- Parameters: None
- Returns: None
DebugKeyHandler_S()
- Description: Triggers a world save event remotely or locally when Ctrl is held.
- Parameters: None
- Returns: boolean, true
- Error states: Returns nil if Ctrl is not held
DebugKeyHandler_KP_MULTIPLY()
- Description: Gives a devtool item if debug toggle is enabled.
- Parameters: None
- Returns: boolean, true
- Error states: Returns nil if debug toggle is disabled
DebugKeyHandler_KP_DIVIDE_GAME()
- Description: Drops everything from the debug key player inventory if debug toggle is enabled.
- Parameters: None
- Returns: boolean, true
- Error states: Returns nil if debug toggle is disabled or no player
DebugKeyHandler_C()
- Description: Resets colour cube or teleports selected entity to rookery based on user name and modifiers.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_PAUSE()
- Description: Toggles debug pause and debug camera, configuring render settings.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_H()
- Description: Toggles HUD, forces hounded wave, or cycles through herd members based on modifiers.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_J()
- Description: Triggers periodic spawner or sets mood on selected entity based on Shift key.
- Parameters: None
- Returns: boolean, true
DebugKeyHandler_INSERT()
- Description: Enables debug render, toggles debug camera, or toggles physics render based on modifiers.
- Parameters: None
- Returns: boolean, true
- Error states: Returns nil if debug toggle is disabled
DebugKeyHandler_I()
- Description: Spawns dragonfly, light flower, or locks lavae targets based on modifiers.
- Parameters: None
- Returns: boolean, true
DebugRMB(x, y)
- Description: Handles right mouse button debug actions including spawning selected prefab, removing entities, killing entities under cursor, or inspecting entities.
- Parameters:
x-- number, screen or world x coordinatey-- number, screen or world y coordinate
- Returns: nil
DebugLMB(x, y)
- Description: Handles left mouse button debug action to set debug entity if simulation is paused.
- Parameters:
x-- number, screen or world x coordinatey-- number, screen or world y coordinate
- Returns: nil
d_addemotekeys()
- Description: Registers numpad keys to trigger specific player emote user commands.
- Parameters: None
- Returns: nil
d_gettiles()
- Description: Scans a grid around the player for farming soil tiles and prints their coordinates.
- Parameters: None
- Returns: nil
Events & listeners
Listens to:
onattackother-- Listened conditionally on player entity when F1 is pressed
Pushes:
ms_nextnightmarephase-- Pushed on TheWorld to advance nightmare phasems_nextphase-- Pushed on TheWorld to advance day phasems_advanceseason-- Pushed on TheWorld to advance seasonspawnnewboatleak-- Pushed on boat entity to spawn a leakboatcollision-- Pushed on boat bumper entity to simulate collisionms_sendlightningstrike-- Pushed on TheWorld to trigger lightningms_setseasonlength-- Pushed on TheWorld to modify season lengthms_deltawetness-- Pushed to TheWorld to change wetness levelms_deltamoisture-- Pushed to TheWorld to change moisture levelms_setsnowlevel-- Pushed to TheWorld to set snow levelms_retreatseason-- Pushed to TheWorld to retreat the seasonms_save-- Pushed to TheWorld to trigger a save