Debugkeys
Based on game build 722832 | Last updated: 2026-04-18
Overview
debugkeys.lua is a core debug utility module that enables developers to interact with the game through keyboard shortcuts and debug commands. It registers global and game-specific key handlers, defines multiple key binding tables for different debug purposes, and provides functions for spawning entities, manipulating game state, inspecting components, and triggering world events. This file is loaded for debug builds; specific features are disabled on Steam Deck via IsSteamDeck() check, and cheat-related functionality is gated by CHEATS_ENABLED within the file. It interacts extensively with entity components, world systems, and the frontend debug UI.
Usage example
-- Debugkeys is automatically loaded when cheats are enabled
-- Register a custom debug key handler
AddGameDebugKey(KEY_Z, function()
local player = ConsoleCommandPlayer()
if player then
player.components.health:DoDelta(10, nil, "debug_key")
end
return true
end)
-- Register a global debug key (works outside gameplay)
AddGlobalDebugKey(KEY_F12, function()
TheSim:ToggleDebugPause()
return true
end)
-- Access key binding tables
for _, binding in ipairs(GLOBAL_KEY_BINDINGS) do
print(binding.name, binding.binding.key)
end
Dependencies & tags
External dependencies:
dbui_no_package/debug_nodes-- conditional require for debug UI panels (CAN_USE_DBUI)dbui_no_package/debug_entity-- debug entity paneldbui_no_package/debug_prefabs-- debug prefabs paneldbui_no_package/debug_audio-- debug audio paneldbui_no_package/debug_weather-- debug weather paneldbui_no_package/debug_skins-- debug skins paneldbui_no_package/debug_widget-- debug widget paneldbui_no_package/debug_player-- debug player paneldbui_no_package/debug_input-- debug input paneldbui_no_package/debug_strings-- debug strings paneldbui_no_package/debug_console-- debug console paneldbui_no_package/debug_watch-- debug watch paneldbui_no_package/debug_anything-- debug anything paneldbui_no_package/debug_history-- debug history panelconsolecommands-- console command functions (c_spawn, c_give, etc.)map/levels-- level data for room/task inspectionmap/tasks-- task definitionsmap/tasksets-- task set definitionsmap/rooms-- room definitionsprefabs/skilltree_defs-- skill tree definitions for debugusercommands-- user command execution for emotes
Components used:
cooldown-- LongUpdate, cooldown_duration accessed for debug resetdomesticatable-- BecomeDomesticated, BecomeFeral, IsDomesticated, tendenciesfarming_manager-- AddTileNutrients, GetTileNutrients for tile manipulationfueled-- SetPercent for refueling entitiesgrowable-- DoGrowth for forcing growth stagesharvestable-- Grow for producing harvestable itemshealth-- DoDelta, Kill, maxhealth for health manipulationhunger-- DoDelta for hunger modificationinventory-- DropEverything, Equip for inventory managementinventoryitem-- SetLanded for item state on boat teleportknownlocations-- GetLocation for teleporting to known locationslocomotor-- accessed for target selectionmood-- SetIsInMood for mood state forcingperiodicspawner-- TrySpawn for forcing spawn eventsperishable-- Perish for forcing spoilagepickable-- Pick, Regen for plant interactionsanity-- DoDelta for sanity modificationsetter-- SetSetTime, StartSetting for setting timersskilltreeupdater-- AddSkillXP, DeactivateSkill, GetSkillXP for skill debugwalkableplatform-- GetPlayersOnPlatform for boat platform handlingherd-- members table accessherdmember-- herd reference for herd navigationhounded-- ForceNextWave for triggering hound attacks
Tags:
player-- checked for player entity identificationboatbumper-- used in boat collision debug_inventoryitem-- used in boat teleport item filteringFX,NOCLICK,DECOR,INLIMBO-- exclusion tags for entity filteringwall-- exclusion tag for right-click debug entity filtering
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
handlers | table | {} | Global table storing registered debug key handler functions keyed by key code. |
GLOBAL_KEY_BINDINGS | table | — | Array of key binding definitions for general debug functions (pause, god mode, etc.). |
PROGRAMMER_KEY_BINDINGS | table | — | Array of key binding definitions for programmer-specific debug functions (perf graph, world select). |
WINDOW_KEY_BINDINGS | table | — | Array of key binding definitions for debug UI panel windows (prefabs, audio, entity, etc.). |
Main functions
DoDebugKey(key, down)
- Description: Called by frontend code when a raw key event has not been consumed by the current screen. Iterates through registered handlers for the key and executes them if the down state matches.
- Parameters:
key-- key code constant (e.g., KEY_HOME, KEY_F1)down-- boolean indicating key press (true) or release (false)
- Returns:
trueif a handler consumed the event,nilotherwise. - Error states: None.
AddGameDebugKey(key, fn, down)
- Description: Registers a debug key handler that only activates during gameplay (
inGamePlayis true). Used for in-game debug functions. - Parameters:
key-- key code constantfn-- function to execute when key is presseddown-- boolean for key state match (defaulttrue)
- Returns: None
- Error states: None.
AddGlobalDebugKey(key, fn, down)
- Description: Registers a debug key handler that activates globally (works outside gameplay, in menus, lobby, etc.).
- Parameters:
key-- key code constantfn-- function to execute when key is presseddown-- boolean for key state match (defaulttrue)
- Returns: None
- Error states: None.
SimBreakPoint()
- Description: Toggles debug pause on the simulation if not already paused. Used for breaking execution in debug builds.
- Parameters: None
- Returns: None
- Error states: None.
DoReload()
- Description: Reloads the scripts/reload.lua module by clearing it from package.loaded and requiring it again. Used for hot-reloading code changes.
- Parameters: None
- Returns: None
- Error states: None.
DebugKeyPlayer()
- Description: Returns the console command player entity if on master sim and TheWorld exists. Used as a safe player reference for debug operations.
- Parameters: None
- Returns: Player entity or
nilif conditions not met. - Error states: None.
d_c_spawn(prefab, count, dontselect)
- Description: Wrapper around c_spawn that handles network replication. Sends ConsoleRemote call on client, executes directly on master sim.
- Parameters:
prefab-- string prefab name to spawncount-- number of instances to spawn (default1)dontselect-- boolean to skip auto-selection of spawned entity
- Returns: None
- Error states: None.
d_c_give(prefab, count, dontselect)
- Description: Wrapper around c_give that handles network replication. Gives items to player inventory with proper client/server handling.
- Parameters:
prefab-- string prefab name to givecount-- number of items to givedontselect-- boolean flag (unused for give)
- Returns: None
- Error states: None.
d_c_remove(entity)
- Description: Removes an entity with network-safe handling. Uses mouse entity if none provided. Sends network ID and position to server on client. Calls
c_remove()as fallback if entity Network component is nil on client. - Parameters:
entity-- entity to remove ornilto use entity under mouse - Returns: None
- Error states: None.
d_c_removeall(entity)
- Description: Removes all entities of the same prefab type as the target entity. Uses mouse entity if none provided.
- Parameters:
entity-- reference entity for prefab type ornilto use entity under mouse - Returns: None
- Error states: None.
Spawn(prefab)
- Description: Simple wrapper around SpawnPrefab for debug spawning. Commented LoadPrefabs call suggests prefabs should be pre-loaded.
- Parameters:
prefab-- string prefab name - Returns: Spawned entity instance.
- Error states: None.
try_boat_teleport(boat, x, y, z)
- Description: Teleports a boat entity and all items on it to a new position. Handles physics constraints and player camera snapping.
- Parameters:
boat-- boat entity with walkableplatform componentx-- target X world positiony-- target Y world positionz-- target Z world position
- Returns:
trueon success. - Error states: May fail if boat lacks required components (Physics, walkableplatform).
DebugRMB(x, y)
- Description: Handles right mouse button debug actions. Supports spawn selected prefab, remove entities, kill nearby entities, set debug entity based on modifier keys.
- Parameters:
x-- screen X positiony-- screen Y position
- Returns: None
- Error states: None.
DebugLMB(x, y)
- Description: Handles left mouse button debug actions. Sets debug entity when simulation is paused.
- Parameters:
x-- screen X positiony-- screen Y position
- Returns: None
- Error states: None.
DoDebugMouse(button, down, x, y)
- Description: Main mouse event handler for debug input. Routes to DebugRMB or DebugLMB based on button. Only processes on button down.
- Parameters:
button-- mouse button constant (MOUSEBUTTON_LEFT, MOUSEBUTTON_RIGHT)down-- boolean for button statex-- screen X positiony-- screen Y position
- Returns: Returns
falseifdownisfalse; otherwise returnsnil(handlers do not return a value). - Error states: None.
d_addemotekeys()
- Description: Registers keypad number keys (KP_0 through KP_9, KP_PERIOD) to trigger user command emotes (sit, happy, joy, slowclap, no, angry, facepalm, impatient, shrug, wave, fistshake).
- Parameters: None
- Returns: None
- Error states: None.
d_gettiles()
- Description: Scans a 11x11 grid around the player for FARMING_SOIL tiles and prints their coordinates. Used for farm plot debugging.
- Parameters: None
- Returns: None (prints to console).
- Error states: None.
BindKeys(bindings)
- Description: Iterates through a binding table and registers each binding via AddGlobalDebugKey. Handles modifier key checks (CTRL, SHIFT, ALT) before executing the bound function.
- Parameters:
bindings-- array of binding definition tables with binding, name, fn, down fields - Returns: None
- Error states: None.
Events & listeners
Listens to: None
Pushes:
ms_nextnightmarephase-- triggered by SHIFT+F10 to advance nightmare phasems_nextphase-- triggered by F10 to advance day phasems_advanceseason-- triggered by F3 or PAGEUP to advance seasonms_retreatseason-- triggered by PAGEDOWN to retreat seasonms_deltawetness-- triggered by PAGEUP/PAGEDOWN with SHIFT for wetness adjustmentms_deltamoisture-- triggered by PAGEUP/PAGEDOWN with CTRL for moisture adjustmentms_setsnowlevel-- triggered by PAGEUP/PAGEDOWN with ALT for snow level adjustmentms_sendlightningstrike-- triggered by SHIFT+F5 for lightning strike at positionms_setseasonlength-- triggered by F5 to set season lengthsms_save-- triggered by CTRL+S to save gamespawnnewboatleak-- pushed to boat entity for debug leak spawningboatcollision-- pushed to boat bumper for collision debug