Console variables (cvars) and commands let you expose configuration values and callable actions through the in-game console. Use them to tune gameplay settings, add debug commands, or expose settings to players.
Console commands
A console command is a static method decorated with [ConCmd]. When the player types the command name in the console, s&box calls the method.
[ConCmd( "hello" )]
static void HelloCommand()
{
Log.Info( "Hello there!" );
}
Commands can accept arguments. s&box converts the console input string to the declared parameter types automatically.
[ConCmd( "hello" )]
static void HelloCommand( string name )
{
Log.Info( $"Hello there {name}!" );
}
s&box will do its best to convert arguments from strings to the types your method declares.
Server commands
Add ConVarFlags.Server to run the command on the server regardless of who invokes it. If you add a Connection parameter first, s&box passes in the caller’s connection so you can identify who ran the command.
[ConCmd( "test", ConVarFlags.Server )]
public static void TestCmd( Connection caller )
{
Log.Info( "The caller is: " + caller.DisplayName );
}
Use ConVarFlags.Server for any command that modifies authoritative game state to ensure it only runs where it’s safe to do so.
Console variables
A console variable is a static property decorated with [ConVar]. Players and code can read and set its value through the console.
[ConVar]
public static bool debug_bullets { get; set; } = false;
Flags
Use ConVarFlags to control how a cvar behaves. You can combine flags.
// Persists between sessions — saved to disk and restored on startup
[ConVar( "bullet_count", ConVarFlags.Saved )]
public static int BulletCount { get; set; } = 6;
// Only the host can change it; its value is synced to all clients
[ConVar( "friendly_fire", ConVarFlags.Replicated )]
public static bool FriendlyFire { get; set; } = false;
// Sent to the host in UserInfo, available via the player's Connection
[ConVar( "view_mode", ConVarFlags.UserInfo )]
public static string ViewMode { get; set; } = "firstperson";
// Hidden from autocomplete and console find
[ConVar( "secret", ConVarFlags.Hidden )]
public static int SecretVariableMode { get; set; } = 3;
ConVarFlags.Hidden works on ConCmd too — use it to hide debug commands from player-facing autocomplete.
Game settings
Use ConVarFlags.GameSetting to expose a cvar on the game creation screen. Pair it with a [Range] attribute to render it as a slider.
// Shows up in the game creation screen as a slider
[ConVar( "player_speed", ConVarFlags.GameSetting ), Range( 50f, 1024f, 1 )]
public static float PlayerSpeed { get; set; } = 250f;
This is useful for letting server hosts configure your game without touching the console directly.