menu_bookDocumentation
Console Variables and Commands: ConVar and ConCmd Runtime Configuration
s&box provides console variables (ConVar) and console commands (ConCmd) for runtime configuration and debugging.
Console Commands
Static methods with [ConCmd] attribute:
CSHARP
[ConCmd("hello")]
static void HelloCommand( string name )
{
Log.Info( $"Hello there {name}!" );
}Server Commands
Add ConVarFlags.Server to run on the server. Use Connection as first parameter to identify the caller:
CSHARP
[ConCmd( "test", ConVarFlags.Server )]
public static void TestCmd( Connection caller )
{
Log.Info( "The caller is: " + caller.DisplayName );
}Console Variables
Static properties with [ConVar] attribute:
CSHARP
[ConVar]
public static bool debug_bullets { get; set; } = false;ConVar Flags
CSHARP
// Persists between sessions
[ConVar( "bullet_count", ConVarFlags.Saved )]
public static int BulletCount { get; set; } = 6;
// Host-only, synced to all clients
[ConVar( "friendly_fire", ConVarFlags.Replicated )]
public static bool FriendlyFire { get; set; } = false;
// Sent to host in UserInfo via Connection
[ConVar( "view_mode", ConVarFlags.UserInfo )]
public static string ViewMode { get; set; } = "firstperson";
// Hidden from autocomplete
[ConVar( "secret", ConVarFlags.Hidden )]
public static int SecretVariable { get; set; } = 3;Game Settings
Use ConVarFlags.GameSetting to expose settings on the game creation screen:
CSHARP
[ConVar( "player_speed", ConVarFlags.GameSetting ), Range( 50f, 1024f, 1 )]
public static float PlayerSpeed { get; set; } = 250f;
Was this helpful?