Debugkeys
Based on game build 714014 | Last updated: 2026-03-10
Overview
The debugkeys module implements a central debug input system for Don't Starve Together. It registers keyboard and mouse handlers that modify game state, spawn or remove entities, manipulate components (e.g., health, sanity, growth), inspect tile data, trigger world events, and support development workflows like reloading scripts and teleports. These debug commands are only active during development or modded environments and are not intended for production play. The system uses both global and game-contextual key handlers, with support for modifier keys (CTRL, SHIFT, ALT) to vary behavior, and correctly routes actions across client and master simulation.
Usage example
-- Register a new debug key to toggle player godmode
AddGameDebugKey("G", function()
local player = ThePlayer
if player and player.components.health then
player.components.health.isgodmode = not player.components.health.isgodmode
print("Godmode: " .. tostring(player.components.health.isgodmode))
end
end, true)
-- Trigger a debug right-click to spawn selected entity at mouse position
DebugRMB(TheInput:GetWorldPosition())
-- Force reload debug scripts for live iteration
DoReload()
Dependencies & tags
Components used:
cooldown(LongUpdate,cooldown_duration)domesticatable(BecomeDomesticated,BecomeFeral,IsDomesticated,tendencies)farming_manager(AddTileNutrients,GetTileNutrients)fueled(SetPercent)growable(DoGrowth)harvestable(Grow)health(DoDelta,Kill,maxhealth)herd(members)herdmember(herd)hounded(ForceNextWave)hunger(DoDelta)inventory(DropEverything,Equip)inventoryitem(SetLanded)knownlocations(GetLocation)locomotor(no methods used)mood(SetIsInMood)periodicspawner(TrySpawn)perishable(Perish)pickable(Pick,Regen)pinnable(Stick,Unstick,IsStuck)sanity(DoDelta,SetPercent)setter(SetSetTime,StartSetting)skilltreeupdater(no methods used)temperature(DoDelta)walkableplatform(no methods used)
Tags:
playerboatbumperFXNOCLICKDECORINLIMBO_inventoryitemChester_Eyebonewitheredwallwithered
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
self.inst | entity | N/A | The entity instance that owns this component (here, the debug module itself is not a standard component; self refers to the debug keys module). |
CAN_USE_DBUI | boolean | N/A | Conditional flag used to enable DBUI-based debug panels. |
TheInput | TheInput | N/A | Global input system used for key/mouse state. |
ThePlayer | player entity | N/A | The local player entity when in-game. |
TheWorld | World | N/A | The global world instance. |
TheSim | TheSim | N/A | Global simulation control object. |
TheFrontEnd | FrontEnd | N/A | Frontend UI state manager. |
Main functions
dumpvariabletostr(var)
- Description: Converts any Lua variable to a human-readable string suitable for debugging output (e.g., console, log). Handles
nil,boolean,number,string,table,function, anduserdatatypes. - Parameters:
var— any Lua value. - Returns:
string— formatted representation ofvar.
d_c_spawn(prefab, count, dontselect)
- Description: Spawns
countinstances of the givenprefab. Handles client–server replication: dispatches remotely if not on master simulation; otherwise callsc_spawndirectly. - Parameters:
prefab— string, name of the prefab to spawn.count— number, number of instances.dontselect— boolean, iftrue, do not auto-select the first spawned entity.
- Returns:
nil.
d_c_give(prefab, count, dontselect)
- Description: Gives
countinstances ofprefabto the player (viac_give). Handles client–server replication similar tod_c_spawn. - Parameters: Same as
d_c_spawn. - Returns:
nil.
d_c_remove(entity)
- Description: Removes a single entity: the one under the mouse cursor if
entityis omitted; otherwise removes the providedentity. Replicated across networks if needed. - Parameters:
entity— optional entity to remove. - Returns:
nil.
d_c_removeall(entity)
- Description: Removes all entities matching the prefab of
entity(or the mouse entity if omitted), useful for clearing clutter. - Parameters:
entity— optional entity to define the prefab to remove. - Returns:
nil.
DebugKeyPlayer()
- Description: Returns the player entity used for debug key actions, but only on master simulation. Otherwise returns
nil. - Parameters: None.
- Returns:
player entityornil.
DoDebugKey(key, down)
- Description: Invokes registered handlers for the given
key, passing whether the event is key-down or key-up. - Parameters:
key— string, identifier for the key.down— boolean,truefor key press,falsefor release.
- Returns:
trueif any handler returnstrue; otherwisenil.
AddGameDebugKey(key, fn, down)
- Description: Registers a debug handler that only executes when
inGamePlayistrue. Commonly used for gameplay-specific debug features. - Parameters:
key— string, key identifier.fn— function, callback executed whenkeyis pressed/released.down— boolean (defaulttrue), whether to trigger on key down (true) or key up (false).
- Returns:
nil.
AddGlobalDebugKey(key, fn, down)
- Description: Registers a debug handler that runs regardless of current game state (e.g., menu, loading, gameplay).
- Parameters: Same as
AddGameDebugKey, but noinGamePlaycheck is enforced. - Returns:
nil.
SimBreakPoint()
- Description: Toggles debug pause mode on or off. Only toggles if not already paused.
- Parameters: None.
- Returns:
nil.
DoReload()
- Description: Forces a reload of
scripts/reload.luaby removing it frompackage.loadedand re-require-ing. Enables hot-reloading development scripts. - Parameters: None.
- Returns:
nil.
BindKeys(bindings)
- Description: Registers multiple debug key bindings at once. Each binding must contain
binding(e.g.,"G"or"GALT"),name, andfn. Checks modifier keys before calling the handler. - Parameters:
bindings— array of binding objects. - Returns:
nil.
try_boat_teleport(boat, x, y, z)
- Description: Teleports a boat and all attached players/items to new world coordinates. Snaps player cameras to the boat and moves entities using
Vector3. - Parameters:
boat— entity, the boat to teleport.x,y,z— numbers, target world coordinates.
- Returns:
trueon success;falseotherwise.
d_addemotekeys()
- Description: Registers Numpad key bindings (e.g.,
KEY_KP1–KEY_KP0) for emote commands by invokingUserCommands.RunUserCommand. - Parameters: None.
- Returns:
nil.
d_gettiles()
- Description: Iterates over an 11×11 grid centered on the player, finds all
WORLD_TILES.FARMING_SOILtiles, and logs their world coordinates usingdumptable. - Parameters: None.
- Returns:
nil.
DebugRMB(x, y)
- Description: Handles debug right-click: depending on modifiers and selection state, may spawn, remove, or teleport entities, compute distance/angle, or set a debug entity.
- Parameters:
x,y— numbers, world coordinates fromTheInput:GetWorldPosition().
- Returns:
nil.
DebugLMB(x, y)
- Description: On left-click during debug pause, sets the selected debug entity to the entity under the mouse.
- Parameters: Same as
DebugRMB. - Returns:
nil.
DoDebugMouse(button, down, x, y)
- Description: Entry point for debug mouse handling. Routes to
DebugRMBorDebugLMBonly whendownistrue. - Parameters:
button—MOUSEBUTTON_RIGHTorMOUSEBUTTON_LEFT.down— boolean, only processes whentrue.x,y— numbers, world coordinates.
- Returns:
falseifnot down; otherwise result of handler.
Events & listeners
- Pushes
"domesticated"— byDomesticatable:BecomeDomesticated(). - Pushes
"healthdelta"— byHealth:DoDelta()andHealth:Kill(). - Pushes
"perished"— byPerishable:Perish(). - Pushes
"picked"— byPickable:Pick(). - Pushes
"sanitydelta"— bySanity:DoDelta(). - Pushes
"goinsane"/"gosane"/"goenlightened"— bySanity:DoDelta()on state change. - Pushes
"on_no_longer_landed"/"on_landed"— byInventoryItem:SetLanded()on landing state change. - World events (via
TheWorld:PushEventin debug handlers):"ms_nextnightmarephase""ms_nextphase""ms_advanceseason""ms_retreatseason""ms_deltawetness""ms_deltamoisture""ms_setsnowlevel""ms_sendlightningstrike""ms_setseasonlength""spawnnewboatleak""boatcollision"