Main
Based on game build 714014 | Last updated: 2026-03-10
Overview
main.lua serves as the primary entry point for the Don't Starve Together game runtime. It performs critical low-level setup: overriding Lua module paths, setting up platform detection helpers, initializing global state, registering custom loaders, loading essential subsystems (e.g., mods, tuning, language, networking), and executing the core startup sequence via ModSafeStartup(). It does not define a traditional component but orchestrates global initialization for the entire game process.
Usage example
main.lua is automatically executed during game startup and is not added or invoked as a component. Typical interaction occurs implicitly through its exported configuration constants and global state. For example:
if IsSteam() then
print("Running on Steam platform")
end
if CHEATS_ENABLED then
TheSim:EnableCheats(true)
end
Dependencies & tags
Components used: None (this is a root initialization script, not an entity component).
Tags: None (does not operate on entities).
Properties
No public properties are defined as instance variables (since this is not a component class). It defines global constants and tables:
MAIN = 1ENCODE_SAVESCHEATS_ENABLEDCAN_USE_DBUIDEBUG_MENU_ENABLEDGAME_SERVERGameplayOptions = {}Prefabs,Ents,AwakeEnts, etc. (entity tracking tables)- Global variables such as
TheGlobalInstance,TheCamera,TheWorld,ThePlayer,AllPlayers,EventAchievements,TheRecipeBook,TheCookbook,ThePlantRegistry,TheSkillTree,TheGenericKV,TheScrapbookPartitions,TheCraftingMenuProfile,Lavaarena_CommunityProgression,TheLoadingTips,SaveGameIndex,ShardGameIndex,ShardSaveGameIndex,CustomPresetManager,HashesMessageState,LastUIRoot,IsIntegrityChecking, andTheMixer.
Main functions
No functions defined in this file are callable as component methods. This file contains global functions and initialization logic. The following are key global functions defined in the file:
IsConsole()
- Description: Returns
trueif the game is running on a console platform (PS4, Xbox One, or Switch). - Parameters: None.
- Returns:
trueif on console; otherwisefalse.
IsNotConsole()
- Description: Returns
trueif the game is not running on a console. - Parameters: None.
- Returns:
trueif on PC (Windows, Linux, macOS); otherwisefalse.
IsPS4(), IsPS5(), IsPSN(), IsXB1(), IsSteam(), IsWin32(), IsLinux(), IsRail(), IsSteamDeck()
- Description: Platform detection helpers that return
truefor specific platform or store configurations. - Parameters: None.
- Returns: Boolean indicating platform membership.
ValidateLineNumber(num)
- Description: Forwards line number validation to the underlying
TheSiminstance (if available). Used for debugging and editor integration. - Parameters:
num(number) — the line number to validate. - Returns: Nothing.
loadfn(modulename) (internal loader)
- Description: Custom Lua module loader used to load mod Lua files with mod manifest awareness. Used by
package.loadersto resolverequire()calls. - Parameters:
modulename(string) — dot-separated module path (e.g.,"modname/scripts/mymod"). - Returns: A loaded module or an error message string.
- Error states: Returns an error string if the file is not found.
ModSafeStartup()
- Description: The core startup function that initializes game systems, loads mods, instantiates global prefabs (
global,event_deps), and builds global entities (TheGlobalInstance,TheCamera, etc.). It runs after mod index loading finishes (or synchronously if mods are disabled). - Parameters: None.
- Returns: Nothing.
- Error states: None documented; assumed to be fatal on critical failure.
Events & listeners
This file does not register or push game events via inst:ListenForEvent or inst:PushEvent. It performs top-level initialization before entities or components exist.