menu_bookDocumentation
Console Variables and Commands: ConVar and ConCmd with Flags
Console variables ([ConVar]) and commands ([ConCmd]) let you create tweakable settings and runnable commands accessible from the s&box console.
Console Commands
Static methods with [ConCmd]:
CSHARP
[ConCmd( "hello" )]
static void HelloCommand( string name )
{
Log.Info( $"Hello there {name}!" );
}Arguments are auto-converted from strings to the specified types.
Server Commands
Run on the server with ConVarFlags.Server. Use Connection as first parameter to identify the caller:
CSHARP
[ConCmd( "test", ConVarFlags.Server )]
public static void TestCmd( Connection caller )
{
Log.Info( "Caller: " + caller.DisplayName );
}Console Variables
Static properties with [ConVar]:
CSHARP
[ConVar]
public static bool debug_bullets { get; set; } = false;ConVar Flags
CSHARP
// Persists between sessions (saved to disk)
[ConVar( "bullet_count", ConVarFlags.Saved )]
public static int BulletCount { get; set; } = 6;
// Host-only, value synced to all clients
[ConVar( "friendly_fire", ConVarFlags.Replicated )]
public static bool FriendlyFire { get; set; } = false;
// Sent to host in UserInfo (available via Connection)
[ConVar( "view_mode", ConVarFlags.UserInfo )]
public static string ViewMode { get; set; } = "firstperson";
// Hidden from autocomplete
[ConVar( "secret", ConVarFlags.Hidden )]
public static int SecretMode { get; set; } = 3;Game Settings
Expose a ConVar to the game creation screen with ConVarFlags.GameSetting:
CSHARP
[ConVar( "player_speed", ConVarFlags.GameSetting ), Range( 50f, 1024f, 1 )]
public static float PlayerSpeed { get; set; } = 250f;This shows as a configurable slider when creating a game lobby.
Was this helpful?