Debugtools
Based on game build 714014 | Last updated: 2026-03-10
Overview
debugtools is a collection of standalone Lua utility functions for debugging and diagnostics in Don't Starve Together. It does not define a component, but rather exports procedural functions and utilities (e.g., dprint, dumptable, DebugArcAttackHitBox) that modders can use directly. Key capabilities include formatted stack tracing, recursive table inspection, conditional console output based on environment variables, and live debug drawing of geometric shapes and arc hitboxes for entity-based attacks.
Usage example
-- Enable debug printing for current user only
DPRINT_USERNAME = TheSim:GetUsersName()
-- Dump a complex table with recursion control
dumptable(my_entity.components.inventory)
-- Log only ifCHEATS_ENABLED and current user matches
dprint("Update tick", frame_count, entity:GetGUID())
-- Visualize an arc attack hitbox (radius 5, 90-degree span)
DebugArcAttackHitBox(player, 90, 1.5, 5, 1.0)
Dependencies & tags
Components used: None (this file is a procedural utility, not a component).
Tags: None identified.
Properties
No public properties. All functionality is exposed via exported functions.
Main functions
dprint(...)
- Description: Conditional debug print to the game's internal log buffer. Only prints if
CHEATS_ENABLEDandCHEATS_ENABLE_DPRINTare true. IfDPRINT_USERNAMEis defined, it also checks that the current user matches. Optionally prepends source file and line number ifDPRINT_PRINT_SOURCELINEis true. - Parameters: Vararg (
...) — values to log. - Returns: Nothing.
- Error states: Silent no-op unless
CHEATS_ENABLEDandCHEATS_ENABLE_DPRINTare true (and optionallyDPRINT_USERNAMEmatches).
dumptable(obj, indent, recurse_levels, visit_table, is_terse)
- Description: Recursively prints the contents of a table to the console with indented key-value pairs. Skips circular references by tracking visited tables.
- Parameters:
obj(table or any) — the table to dump.indent(number, optional) — starting indentation level; defaults to1.recurse_levels(number, optional) — maximum recursion depth; defaults to5.visit_table(table, optional) — internal tracking table for visited objects (do not pass manually).is_terse(boolean, optional) — if true, suppresses "(empty)" and "nil" messages.
- Returns: Nothing.
- Error states: Skips tables already visited (prevents infinite recursion). Skips entity tables by printing "(Entity -- skipping.)".
dumptablequiet(obj, indent, recurse_levels, visit_table)
- Description: Alias for
dumptable(..., true)— same behavior asdumptablebut in "terse" mode (suppresses verbose empty/nil output). - Parameters: Same as
dumptable, withis_terseimplicitlytrue. - Returns: Nothing.
ddump(obj, indent, recurse_levels, root)
- Description: Alternative recursive table dumper that outputs via
dprint()(respecting debug filters) instead of rawprint(). Includes self-reference detection. - Parameters:
obj(table) — the table to dump.indent(number, optional) — indentation level; defaults to1.recurse_levels(number, optional) — max depth; defaults to3.root(table, optional) — internal root table reference to detect cycles.
- Returns: Nothing.
table.inspect = require("inspect")
- Description: Makes the
inspectmodule (for pretty-printing recursive tables) available astable.inspect. (Note: This is a module assignment, not a function.)
debugstack(start, bottom, top)
- Description: Returns a formatted string representing the current Lua call stack, truncated to
topframes from the start andbottomframes from the end if the stack is large. - Parameters:
start(number, optional) — stack level offset to start listing from; defaults to1.bottom(number, optional) — number of bottom frames to show; defaults to10.top(number, optional) — number of top frames to show; defaults to12.
- Returns: String — the formatted stack traceback.
debugstack_oneline(linenum)
- Description: Returns a one-line formatted string for a specific stack level (default
3). - Parameters:
linenum(number, optional) — stack level to format; defaults to3. - Returns: String.
instrument_userdata(instance)
- Description: Wraps a userdata object (e.g.,
TheNet) with a proxy table that prints the call stack before every method call. Useful for tracing who is calling low-level APIs. - Parameters:
instance(userdata) — the userdata object to instrument. - Returns: Table — a proxy with methods that log the full stack before forwarding.
debuglocals(level)
- Description: Returns a string listing all local variables and their values at the specified stack level.
- Parameters:
level(number) — stack level from which to inspect locals (e.g.,2for caller's scope). - Returns: String — formatted as
"varname = value\n...".
printwrap(msg, ...)
- Description: Prints a message, and if the remaining arguments are a table, calls
dumptableto dump it recursively; otherwise prints normally. Returns all original arguments. - Parameters:
msg(string),...— vararg arguments. - Returns: All input arguments unchanged.
printsel(inst, ...)
- Description: Prints only if
instmatches the currently selected entity (viac_sel()). - Parameters:
inst(entity),...— values to print. - Returns: Nothing.
eprint(inst, ...)
- Description: Calls
dprint(...)only ifinstis the debug entity (as returned byGetDebugEntity()). - Parameters:
inst(entity),...— values to log. - Returns: Nothing.
EnableDebugOnEntity(thing, items)
- Description: Configures debug output behavior for a specific entity by setting up a
_DEBUG_Listtable. Supports per-entity debug tags, priority filtering, and enabling/disabling. - Parameters:
thing(table) — the entity/table to enable debug for.items(boolean/string/number) —falseto disable;"on"/"off"to toggle;"all"/string to enable tagging; number to set priority.
- Returns: Nothing.
Dbg(thing, level, ...)
- Description: Conditional debug print for a specific entity. Only prints if debug is enabled for that entity and conditions (
priority,tag, or"all") match. - Parameters:
thing(table) — the entity to check debug settings on.level(string or number) — tag name or priority threshold....— vararg values to print.
- Returns: Nothing.
DrawLine(pos1, pos2)
- Description: Draws a white line between two 3D positions for map debugging. Internally creates a temporary
DebugDrawMapentity and uses its debug renderer. - Parameters:
pos1(table) —{x, y, z}or{x, z}position.pos2(table) —{x, y, z}or{x, z}position.
- Returns: Nothing.
DebugArcAttackHitBox(inst, arc_span, forward_offset, arc_radius, lifetime)
- Description: Draws a thick arc hitbox in front of an entity for debugging attacks. Visualizes the arc using debug-rendered lines with a central and offset lines to represent thickness.
- Parameters:
inst(entity) — entity whose facing direction determines the arc center.arc_span(number) — total angular width of the arc in degrees.forward_offset(number) — forward distance to shift the arc origin.arc_radius(number) — radius of the arc.lifetime(number, optional) — seconds before the debug lines are cleared.
- Returns: Nothing.
Events & listeners
Not applicable.